Inheritance: Org.BouncyCastle.Asn1.Asn1Encodable
Exemple #1
0
 public static int CalculateVersion(OriginatorInfo originatorInfo, Asn1Set recipientInfos, Asn1Set unprotectedAttrs)
 {
     if (originatorInfo != null || unprotectedAttrs != null)
     {
         return(2);
     }
     global::System.Collections.IEnumerator enumerator = recipientInfos.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             object        current  = enumerator.get_Current();
             RecipientInfo instance = RecipientInfo.GetInstance(current);
             if (instance.Version.Value.IntValue != 0)
             {
                 return(2);
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(0);
 }
		public EnvelopedData(
            OriginatorInfo			originatorInfo,
            Asn1Set					recipientInfos,
            EncryptedContentInfo	encryptedContentInfo,
            Asn1Set					unprotectedAttrs)
        {
            if (originatorInfo != null || unprotectedAttrs != null)
            {
                version = new DerInteger(2);
            }
            else
            {
                version = new DerInteger(0);

				foreach (object o in recipientInfos)
				{
                    RecipientInfo ri = RecipientInfo.GetInstance(o);

					if (!ri.Version.Equals(version))
                    {
                        version = new DerInteger(2);
                        break;
                    }
                }
            }

			this.originatorInfo = originatorInfo;
            this.recipientInfos = recipientInfos;
            this.encryptedContentInfo = encryptedContentInfo;
            this.unprotectedAttrs = unprotectedAttrs;
        }
		public AuthEnvelopedData(
			OriginatorInfo			originatorInfo,
			Asn1Set					recipientInfos,
			EncryptedContentInfo	authEncryptedContentInfo,
			Asn1Set					authAttrs,
			Asn1OctetString			mac,
			Asn1Set					unauthAttrs)
		{
			// "It MUST be set to 0."
			this.version = new DerInteger(0);

			this.originatorInfo = originatorInfo;

			// TODO
			// "There MUST be at least one element in the collection."
			this.recipientInfos = recipientInfos;

			this.authEncryptedContentInfo = authEncryptedContentInfo;

			// TODO
			// "The authAttrs MUST be present if the content type carried in
			// EncryptedContentInfo is not id-data."
			this.authAttrs = authAttrs;

			this.mac = mac;

			this.unauthAttrs = unauthAttrs;
	    }
        private AuthEnvelopedData(Asn1Sequence seq)
        {
            int        num        = 0;
            Asn1Object asn1Object = seq[num++].ToAsn1Object();

            this.version = (DerInteger)asn1Object;
            asn1Object   = seq[num++].ToAsn1Object();
            if (asn1Object is Asn1TaggedObject)
            {
                this.originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)asn1Object, false);
                asn1Object          = seq[num++].ToAsn1Object();
            }
            this.recipientInfos           = Asn1Set.GetInstance(asn1Object);
            asn1Object                    = seq[num++].ToAsn1Object();
            this.authEncryptedContentInfo = EncryptedContentInfo.GetInstance(asn1Object);
            asn1Object                    = seq[num++].ToAsn1Object();
            if (asn1Object is Asn1TaggedObject)
            {
                this.authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)asn1Object, false);
                asn1Object     = seq[num++].ToAsn1Object();
            }
            this.mac = Asn1OctetString.GetInstance(asn1Object);
            if (seq.Count > num)
            {
                asn1Object       = seq[num++].ToAsn1Object();
                this.unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)asn1Object, false);
            }
        }
		public CmsAuthEnvelopedData(
			ContentInfo contentInfo)
		{
			this.contentInfo = contentInfo;

			AuthEnvelopedData authEnvData = AuthEnvelopedData.GetInstance(contentInfo.Content);

			this.originator = authEnvData.OriginatorInfo;

			//
	        // read the recipients
	        //
	        Asn1Set recipientInfos = authEnvData.RecipientInfos;

			//
			// read the auth-encrypted content info
			//
			EncryptedContentInfo authEncInfo = authEnvData.AuthEncryptedContentInfo;
			this.authEncAlg = authEncInfo.ContentEncryptionAlgorithm;
			CmsSecureReadable secureReadable = new AuthEnvelopedSecureReadable(this);

			//
			// build the RecipientInformationStore
			//
			this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
				recipientInfos, secureReadable);

			// FIXME These need to be passed to the AEAD cipher as AAD (Additional Authenticated Data)
			this.authAttrs = authEnvData.AuthAttrs;
			this.mac = authEnvData.Mac.GetOctets();
			this.unauthAttrs = authEnvData.UnauthAttrs;
		}
Exemple #6
0
        public AuthenticatedData(
            OriginatorInfo originatorInfo,
            Asn1Set recipientInfos,
            AlgorithmIdentifier macAlgorithm,
            AlgorithmIdentifier digestAlgorithm,
            ContentInfo encapsulatedContent,
            Asn1Set authAttrs,
            Asn1OctetString mac,
            Asn1Set unauthAttrs)
        {
            if (digestAlgorithm != null || authAttrs != null)
            {
                if (digestAlgorithm == null || authAttrs == null)
                {
                    throw new ArgumentException("digestAlgorithm and authAttrs must be set together");
                }
            }

            version = new DerInteger(CalculateVersion(originatorInfo));

            this.originatorInfo          = originatorInfo;
            this.macAlgorithm            = macAlgorithm;
            this.digestAlgorithm         = digestAlgorithm;
            this.recipientInfos          = recipientInfos;
            this.encapsulatedContentInfo = encapsulatedContent;
            this.authAttrs   = authAttrs;
            this.mac         = mac;
            this.unauthAttrs = unauthAttrs;
        }
Exemple #7
0
        private AuthenticatedData(Asn1Sequence seq)
        {
            int num = 0;

            this.version = (DerInteger)seq[num++];
            Asn1Encodable asn1Encodable = seq[num++];

            if (asn1Encodable is Asn1TaggedObject)
            {
                this.originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)asn1Encodable, false);
                asn1Encodable       = seq[num++];
            }
            this.recipientInfos = Asn1Set.GetInstance(asn1Encodable);
            this.macAlgorithm   = AlgorithmIdentifier.GetInstance(seq[num++]);
            asn1Encodable       = seq[num++];
            if (asn1Encodable is Asn1TaggedObject)
            {
                this.digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)asn1Encodable, false);
                asn1Encodable        = seq[num++];
            }
            this.encapsulatedContentInfo = ContentInfo.GetInstance(asn1Encodable);
            asn1Encodable = seq[num++];
            if (asn1Encodable is Asn1TaggedObject)
            {
                this.authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)asn1Encodable, false);
                asn1Encodable  = seq[num++];
            }
            this.mac = Asn1OctetString.GetInstance(asn1Encodable);
            if (seq.Count > num)
            {
                this.unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[num], false);
            }
        }
        public AuthEnvelopedData(
            OriginatorInfo originatorInfo,
            Asn1Set recipientInfos,
            EncryptedContentInfo authEncryptedContentInfo,
            Asn1Set authAttrs,
            Asn1OctetString mac,
            Asn1Set unauthAttrs)
        {
            // "It MUST be set to 0."
            this.version = new DerInteger(0);

            this.originatorInfo = originatorInfo;

            // TODO
            // "There MUST be at least one element in the collection."
            this.recipientInfos = recipientInfos;

            this.authEncryptedContentInfo = authEncryptedContentInfo;

            // TODO
            // "The authAttrs MUST be present if the content type carried in
            // EncryptedContentInfo is not id-data."
            this.authAttrs = authAttrs;

            this.mac = mac;

            this.unauthAttrs = unauthAttrs;
        }
Exemple #9
0
        public EnvelopedData(
            OriginatorInfo originatorInfo,
            Asn1Set recipientInfos,
            EncryptedContentInfo encryptedContentInfo,
            Asn1Set unprotectedAttrs)
        {
            if (originatorInfo != null || unprotectedAttrs != null)
            {
                version = new DerInteger(2);
            }
            else
            {
                version = new DerInteger(0);

                foreach (object o in recipientInfos)
                {
                    RecipientInfo ri = RecipientInfo.GetInstance(o);

                    if (!ri.Version.Equals(version))
                    {
                        version = new DerInteger(2);
                        break;
                    }
                }
            }

            this.originatorInfo       = originatorInfo;
            this.recipientInfos       = recipientInfos;
            this.encryptedContentInfo = encryptedContentInfo;
            this.unprotectedAttrs     = unprotectedAttrs;
        }
		public AuthenticatedData(
			OriginatorInfo		originatorInfo,
			Asn1Set				recipientInfos,
			AlgorithmIdentifier	macAlgorithm,
			AlgorithmIdentifier	digestAlgorithm,
			ContentInfo			encapsulatedContent,
			Asn1Set				authAttrs,
			Asn1OctetString		mac,
			Asn1Set				unauthAttrs)
		{
			if (digestAlgorithm != null || authAttrs != null)
			{
				if (digestAlgorithm == null || authAttrs == null)
				{
					throw new ArgumentException("digestAlgorithm and authAttrs must be set together");
				}
			}

			version = new DerInteger(CalculateVersion(originatorInfo));

			this.originatorInfo = originatorInfo;
			this.macAlgorithm = macAlgorithm;
			this.digestAlgorithm = digestAlgorithm;
			this.recipientInfos = recipientInfos;
			this.encapsulatedContentInfo = encapsulatedContent;
			this.authAttrs = authAttrs;
			this.mac = mac;
			this.unauthAttrs = unauthAttrs;
		}
 public EnvelopedData(OriginatorInfo originatorInfo, Asn1Set recipientInfos, EncryptedContentInfo encryptedContentInfo, Asn1Set unprotectedAttrs)
 {
     this.version              = new DerInteger(EnvelopedData.CalculateVersion(originatorInfo, recipientInfos, unprotectedAttrs));
     this.originatorInfo       = originatorInfo;
     this.recipientInfos       = recipientInfos;
     this.encryptedContentInfo = encryptedContentInfo;
     this.unprotectedAttrs     = unprotectedAttrs;
 }
Exemple #12
0
 public EnvelopedData(OriginatorInfo originatorInfo, Asn1Set recipientInfos, EncryptedContentInfo encryptedContentInfo, Attributes unprotectedAttrs)
 {
     version                   = new DerInteger(CalculateVersion(originatorInfo, recipientInfos, Asn1Set.GetInstance(unprotectedAttrs)));
     this.originatorInfo       = originatorInfo;
     this.recipientInfos       = recipientInfos;
     this.encryptedContentInfo = encryptedContentInfo;
     this.unprotectedAttrs     = Asn1Set.GetInstance(unprotectedAttrs);
 }
Exemple #13
0
        private AuthEnvelopedData(
            Asn1Sequence seq)
        {
            int index = 0;

            // "It MUST be set to 0."
            Asn1Object tmp = seq[index++].ToAsn1Object();

            version = DerInteger.GetInstance(tmp);
            if (!version.HasValue(0))
            {
                throw new ArgumentException("AuthEnvelopedData version number must be 0");
            }

            tmp = seq[index++].ToAsn1Object();
            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++].ToAsn1Object();
            }

            // "There MUST be at least one element in the collection."
            recipientInfos = Asn1Set.GetInstance(tmp);
            if (recipientInfos.Count < 1)
            {
                throw new ArgumentException("AuthEnvelopedData requires at least 1 RecipientInfo");
            }

            tmp = seq[index++].ToAsn1Object();
            authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp);

            tmp = seq[index++].ToAsn1Object();
            if (tmp is Asn1TaggedObject)
            {
                authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
                tmp       = seq[index++].ToAsn1Object();
            }
            else
            {
                // "The authAttrs MUST be present if the content type carried in
                // EncryptedContentInfo is not id-data."
                if (!authEncryptedContentInfo.ContentType.Equals(CmsObjectIdentifiers.Data))
                {
                    if (authAttrs == null || authAttrs.Count < 1)
                    {
                        throw new ArgumentException("authAttrs must be present with non-data content");
                    }
                }
            }

            mac = Asn1OctetString.GetInstance(tmp);

            if (seq.Count > index)
            {
                tmp         = seq[index++].ToAsn1Object();
                unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
            }
        }
 public AuthEnvelopedData(OriginatorInfo originatorInfo, Asn1Set recipientInfos, EncryptedContentInfo authEncryptedContentInfo, Asn1Set authAttrs, Asn1OctetString mac, Asn1Set unauthAttrs)
 {
     this.version                  = new DerInteger(0);
     this.originatorInfo           = originatorInfo;
     this.recipientInfos           = recipientInfos;
     this.authEncryptedContentInfo = authEncryptedContentInfo;
     this.authAttrs                = authAttrs;
     this.mac         = mac;
     this.unauthAttrs = unauthAttrs;
 }
 public EnvelopedData(
     OriginatorInfo originatorInfo,
     Asn1Set recipientInfos,
     EncryptedContentInfo encryptedContentInfo,
     Attributes unprotectedAttrs)
 {
     this.version = new DerInteger(CalculateVersion(originatorInfo, recipientInfos, Asn1Set.GetInstance(unprotectedAttrs)));
     this.originatorInfo = originatorInfo;
     this.recipientInfos = recipientInfos;
     this.encryptedContentInfo = encryptedContentInfo;
     this.unprotectedAttrs = Asn1Set.GetInstance(unprotectedAttrs);
 }
 public OriginatorInfo GetOriginatorInfo()
 {
     originatorInfoCalled = true;
     if (nextObject == null)
     {
         nextObject = seq.ReadObject();
     }
     if (nextObject is Asn1TaggedObjectParser && ((Asn1TaggedObjectParser)nextObject).TagNo == 0)
     {
         Asn1SequenceParser asn1SequenceParser = (Asn1SequenceParser)((Asn1TaggedObjectParser)nextObject).GetObjectParser(16, isExplicit: false);
         nextObject = null;
         return(OriginatorInfo.GetInstance(asn1SequenceParser.ToAsn1Object()));
     }
     return(null);
 }
Exemple #17
0
 public OriginatorInfo GetOriginatorInfo()
 {
     this.originatorInfoCalled = true;
     if (this.nextObject == null)
     {
         this.nextObject = this.seq.ReadObject();
     }
     if (this.nextObject is Asn1TaggedObjectParser && ((Asn1TaggedObjectParser)this.nextObject).TagNo == 0)
     {
         Asn1SequenceParser asn1SequenceParser = (Asn1SequenceParser)((Asn1TaggedObjectParser)this.nextObject).GetObjectParser(16, false);
         this.nextObject = null;
         return(OriginatorInfo.GetInstance(asn1SequenceParser.ToAsn1Object()));
     }
     return(null);
 }
 public static int CalculateVersion(OriginatorInfo originatorInfo, Asn1Set recipientInfos, Asn1Set unprotectedAttrs)
 {
     if (originatorInfo != null || unprotectedAttrs != null)
     {
         return(2);
     }
     foreach (object current in recipientInfos)
     {
         RecipientInfo instance = RecipientInfo.GetInstance(current);
         if (instance.Version.Value.IntValue != 0)
         {
             return(2);
         }
     }
     return(0);
 }
        private AuthEnvelopedData(
            Asn1Sequence seq)
        {
            int index = 0;

            // TODO
            // "It MUST be set to 0."
            Asn1Object tmp = seq[index++].ToAsn1Object();

            version = (DerInteger)tmp;

            tmp = seq[index++].ToAsn1Object();
            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++].ToAsn1Object();
            }

            // TODO
            // "There MUST be at least one element in the collection."
            recipientInfos = Asn1Set.GetInstance(tmp);

            tmp = seq[index++].ToAsn1Object();
            authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp);

            tmp = seq[index++].ToAsn1Object();
            if (tmp is Asn1TaggedObject)
            {
                authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
                tmp       = seq[index++].ToAsn1Object();
            }
            else
            {
                // TODO
                // "The authAttrs MUST be present if the content type carried in
                // EncryptedContentInfo is not id-data."
            }

            mac = Asn1OctetString.GetInstance(tmp);

            if (seq.Count > index)
            {
                tmp         = seq[index++].ToAsn1Object();
                unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
            }
        }
Exemple #20
0
 public AuthenticatedData(OriginatorInfo originatorInfo, Asn1Set recipientInfos, AlgorithmIdentifier macAlgorithm, AlgorithmIdentifier digestAlgorithm, ContentInfo encapsulatedContent, Asn1Set authAttrs, Asn1OctetString mac, Asn1Set unauthAttrs)
 {
     //IL_001b: Unknown result type (might be due to invalid IL or missing references)
     if ((digestAlgorithm != null || authAttrs != null) && (digestAlgorithm == null || authAttrs == null))
     {
         throw new ArgumentException("digestAlgorithm and authAttrs must be set together");
     }
     version                 = new DerInteger(CalculateVersion(originatorInfo));
     this.originatorInfo     = originatorInfo;
     this.macAlgorithm       = macAlgorithm;
     this.digestAlgorithm    = digestAlgorithm;
     this.recipientInfos     = recipientInfos;
     encapsulatedContentInfo = encapsulatedContent;
     this.authAttrs          = authAttrs;
     this.mac                = mac;
     this.unauthAttrs        = unauthAttrs;
 }
Exemple #21
0
        public static int CalculateVersion(OriginatorInfo origInfo)
        {
            if (origInfo == null)
            {
                return(0);
            }
            else
            {
                int ver = 0;

                foreach (object obj in origInfo.Certificates)
                {
                    if (obj is Asn1TaggedObject)
                    {
                        Asn1TaggedObject tag = (Asn1TaggedObject)obj;

                        if (tag.TagNo == 2)
                        {
                            ver = 1;
                        }
                        else if (tag.TagNo == 3)
                        {
                            ver = 3;
                            break;
                        }
                    }
                }

                foreach (object obj in origInfo.Crls)
                {
                    if (obj is Asn1TaggedObject)
                    {
                        Asn1TaggedObject tag = (Asn1TaggedObject)obj;

                        if (tag.TagNo == 1)
                        {
                            ver = 3;
                            break;
                        }
                    }
                }

                return(ver);
            }
        }
		private AuthEnvelopedData(
			Asn1Sequence	seq)
		{
			int index = 0;

			// TODO
			// "It MUST be set to 0."
			Asn1Object tmp = seq[index++].ToAsn1Object();
			version = (DerInteger)tmp;

			tmp = seq[index++].ToAsn1Object();
			if (tmp is Asn1TaggedObject)
			{
				originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
				tmp = seq[index++].ToAsn1Object();
			}

			// TODO
			// "There MUST be at least one element in the collection."
			recipientInfos = Asn1Set.GetInstance(tmp);

			tmp = seq[index++].ToAsn1Object();
			authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp);

			tmp = seq[index++].ToAsn1Object();
			if (tmp is Asn1TaggedObject)
			{
				authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
				tmp = seq[index++].ToAsn1Object();
			}
			else
			{
				// TODO
				// "The authAttrs MUST be present if the content type carried in
				// EncryptedContentInfo is not id-data."
			}

			mac = Asn1OctetString.GetInstance(tmp);

			if (seq.Count > index)
			{
				tmp = seq[index++].ToAsn1Object();
				unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
			}
		}
Exemple #23
0
        public static int CalculateVersion(OriginatorInfo originatorInfo, Asn1Set recipientInfos, Asn1Set unprotectedAttrs)
        {
            if (originatorInfo != null || unprotectedAttrs != null)
            {
                return(2);
            }

            foreach (object o in recipientInfos)
            {
                RecipientInfo ri = RecipientInfo.GetInstance(o);

                if (ri.Version.IntValueExact != 0)
                {
                    return(2);
                }
            }

            return(0);
        }
Exemple #24
0
        public EnvelopedData(Asn1Sequence seq)
        {
            int num = 0;

            version = (DerInteger)seq[num++];
            object obj = seq[num++];

            if (obj is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)obj, explicitly: false);
                obj            = seq[num++];
            }
            recipientInfos       = Asn1Set.GetInstance(obj);
            encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[num++]);
            if (seq.Count > num)
            {
                unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[num], explicitly: false);
            }
        }
Exemple #25
0
        private AuthenticatedData(
            Asn1Sequence seq)
        {
            int index = 0;

            version = (DerInteger)seq[index++];

            Asn1Encodable tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++];
            }

            recipientInfos = Asn1Set.GetInstance(tmp);
            macAlgorithm   = AlgorithmIdentifier.GetInstance(seq[index++]);

            tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)tmp, false);
                tmp             = seq[index++];
            }

            encapsulatedContentInfo = ContentInfo.GetInstance(tmp);

            tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
                tmp       = seq[index++];
            }

            mac = Asn1OctetString.GetInstance(tmp);

            if (seq.Count > index)
            {
                unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
            }
        }
	    private AuthenticatedData(
	        Asn1Sequence seq)
	    {
	        int index = 0;

	        version = (DerInteger)seq[index++];

	        Asn1Encodable tmp = seq[index++];

	        if (tmp is Asn1TaggedObject)
	        {
	            originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
	            tmp = seq[index++];
	        }

	        recipientInfos = Asn1Set.GetInstance(tmp);
	        macAlgorithm = AlgorithmIdentifier.GetInstance(seq[index++]);

	        tmp = seq[index++];

	        if (tmp is Asn1TaggedObject)
	        {
	            digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)tmp, false);
	            tmp = seq[index++];
	        }

	        encapsulatedContentInfo = ContentInfo.GetInstance(tmp);

	        tmp = seq[index++];

	        if (tmp is Asn1TaggedObject)
	        {
	            authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
	            tmp = seq[index++];
	        }

	        mac = Asn1OctetString.GetInstance(tmp);
	        
	        if (seq.Count > index)
	        {
	            unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
	        }
	    }
        public OriginatorInfo GetOriginatorInfo()
        {
            _originatorInfoCalled = true;

            if (_nextObject == null)
            {
                _nextObject = _seq.ReadObject();
            }

            if (_nextObject is Asn1TaggedObjectParser && ((Asn1TaggedObjectParser)_nextObject).TagNo == 0)
            {
                Asn1SequenceParser originatorInfo = (Asn1SequenceParser)
                                                    ((Asn1TaggedObjectParser)_nextObject).GetObjectParser(Asn1Tags.Sequence, false);
                _nextObject = null;
                return(OriginatorInfo.GetInstance(originatorInfo.ToAsn1Object()));
            }

            return(null);
        }
Exemple #28
0
        public static int CalculateVersion(OriginatorInfo origInfo)
        {
            if (origInfo == null)
            {
                return(0);
            }
            int result = 0;

            foreach (object current in origInfo.Certificates)
            {
                if (current is Asn1TaggedObject)
                {
                    Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)current;
                    if (asn1TaggedObject.TagNo == 2)
                    {
                        result = 1;
                    }
                    else if (asn1TaggedObject.TagNo == 3)
                    {
                        result = 3;
                        break;
                    }
                }
            }
            foreach (object current2 in origInfo.Crls)
            {
                if (current2 is Asn1TaggedObject)
                {
                    Asn1TaggedObject asn1TaggedObject2 = (Asn1TaggedObject)current2;
                    if (asn1TaggedObject2.TagNo == 1)
                    {
                        result = 3;
                        break;
                    }
                }
            }
            return(result);
        }
Exemple #29
0
        public EnvelopedData(
            Asn1Sequence seq)
        {
            int index = 0;

            version = (DerInteger)seq[index++];

            object tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++];
            }

            recipientInfos       = Asn1Set.GetInstance(tmp);
            encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[index++]);

            if (seq.Count > index)
            {
                unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
            }
        }
        public EnvelopedData(
            Asn1Sequence seq)
        {
            int index = 0;

            version = (DerInteger) seq[index++];

            object tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject) tmp, false);
                tmp = seq[index++];
            }

            recipientInfos = Asn1Set.GetInstance(tmp);
            encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[index++]);

            if (seq.Count > index)
            {
                unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject) seq[index], false);
            }
        }
Exemple #31
0
        public AuthEnvelopedData(
            OriginatorInfo originatorInfo,
            Asn1Set recipientInfos,
            EncryptedContentInfo authEncryptedContentInfo,
            Asn1Set authAttrs,
            Asn1OctetString mac,
            Asn1Set unauthAttrs)
        {
            // "It MUST be set to 0."
            this.version = new DerInteger(0);

            this.originatorInfo = originatorInfo;

            // "There MUST be at least one element in the collection."
            this.recipientInfos = recipientInfos;
            if (this.recipientInfos.Count < 1)
            {
                throw new ArgumentException("AuthEnvelopedData requires at least 1 RecipientInfo");
            }

            this.authEncryptedContentInfo = authEncryptedContentInfo;

            // "The authAttrs MUST be present if the content type carried in
            // EncryptedContentInfo is not id-data."
            this.authAttrs = authAttrs;
            if (!authEncryptedContentInfo.ContentType.Equals(CmsObjectIdentifiers.Data))
            {
                if (authAttrs == null || authAttrs.Count < 1)
                {
                    throw new ArgumentException("authAttrs must be present with non-data content");
                }
            }

            this.mac = mac;

            this.unauthAttrs = unauthAttrs;
        }
		internal OriginatorInformation(OriginatorInfo originatorInfo)
		{
			this.originatorInfo = originatorInfo;
		}
Exemple #33
0
 public static OriginatorInfo GetInstance(Asn1TaggedObject obj, bool explicitly)
 {
     return(OriginatorInfo.GetInstance(Asn1Sequence.GetInstance(obj, explicitly)));
 }
Exemple #34
0
        public static int CalculateVersion(OriginatorInfo origInfo)
        {
            if (origInfo == null)
            {
                return(0);
            }
            int result = 0;

            global::System.Collections.IEnumerator enumerator = origInfo.Certificates.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    object current = enumerator.get_Current();
                    if (current is Asn1TaggedObject)
                    {
                        Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)current;
                        if (asn1TaggedObject.TagNo == 2)
                        {
                            result = 1;
                        }
                        else if (asn1TaggedObject.TagNo == 3)
                        {
                            result = 3;
                            break;
                        }
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            enumerator = origInfo.Crls.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    object current2 = enumerator.get_Current();
                    if (current2 is Asn1TaggedObject)
                    {
                        Asn1TaggedObject asn1TaggedObject2 = (Asn1TaggedObject)current2;
                        if (asn1TaggedObject2.TagNo == 1)
                        {
                            return(3);
                        }
                    }
                }
                return(result);
            }
            finally
            {
                global::System.IDisposable disposable2 = enumerator as global::System.IDisposable;
                if (disposable2 != null)
                {
                    disposable2.Dispose();
                }
            }
        }
		public static int CalculateVersion(OriginatorInfo origInfo)
		{
			if (origInfo == null)
				return 0;

			int ver = 0;

			foreach (object obj in origInfo.Certificates)
			{
				if (obj is Asn1TaggedObject)
				{
					Asn1TaggedObject tag = (Asn1TaggedObject)obj;

					if (tag.TagNo == 2)
					{
						ver = 1;
					}
					else if (tag.TagNo == 3)
					{
						ver = 3;
						break;
					}
				}
			}

			foreach (object obj in origInfo.Crls)
			{
				if (obj is Asn1TaggedObject)
				{
					Asn1TaggedObject tag = (Asn1TaggedObject)obj;

					if (tag.TagNo == 1)
					{
						ver = 3;
						break;
					}
				}
			}

			return ver;
		}
        public static int CalculateVersion(OriginatorInfo originatorInfo, Asn1Set recipientInfos, Asn1Set unprotectedAttrs)
        {
            if (originatorInfo != null || unprotectedAttrs != null)
            {
                return 2;
            }

            foreach (object o in recipientInfos)
            {
                RecipientInfo ri = RecipientInfo.GetInstance(o);

                if (ri.Version.Value.IntValue != 0)
                {
                    return 2;
                }
            }

            return 0;
        }