    public static int calculateVersion(OriginatorInfo originatorInfo, ASN1Set recipientInfos, ASN1Set unprotectedAttrs)
    {
        int version;
        if (originatorInfo != null || unprotectedAttrs != null)
        {
            version = 2;
        }
        else
        {
            version = 0;
            Enumeration e = recipientInfos.getObjects();
            while (e.hasMoreElements())
            {
                RecipientInfo   ri = RecipientInfo.getInstance(e.nextElement());
                if (!ri.getVersion().equals(version))
                {
                    version = 2;
                    break;
                }
            }
        }
        return version;
    }

    public static int calculateVersion(OriginatorInfo originatorInfo, ASN1Set recipientInfos, ASN1Set unprotectedAttrs)
    {
        int version;
        if (originatorInfo != null || unprotectedAttrs != null)
        {
            version = 2;
        }
        else
        {
            version = 0;
            Enumeration e = recipientInfos.getObjects();
            while (e.hasMoreElements())
            {
                RecipientInfo   ri = RecipientInfo.getInstance(e.nextElement());
                if (ri.getVersion().getValue().intValue() != version)
                {
                    version = 2;
                    break;
                }
            }
        }
        return version;
    }
