private PrivateKeyInfo(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            IBigInteger version = ((DerInteger) e.Current).Value;
            if (version.IntValue != 0)
            {
                throw new ArgumentException("wrong version for private key info");
            }

            e.MoveNext();
            algID = AlgorithmIdentifier.GetInstance(e.Current);

            try
            {
                e.MoveNext();
                Asn1OctetString data = (Asn1OctetString) e.Current;

                privKey = Asn1Object.FromByteArray(data.GetOctets());
            }
            catch (IOException)
            {
                throw new ArgumentException("Error recoverying private key from sequence");
            }

            if (e.MoveNext())
            {
                attributes = Asn1Set.GetInstance((Asn1TaggedObject) e.Current, false);
            }
        }
		public SemanticsInformation(
			Asn1Sequence seq)
        {
            if (seq.Count < 1)
            {
                throw new ArgumentException("no objects in SemanticsInformation");
            }

			IEnumerator e = seq.GetEnumerator();
			e.MoveNext();
            object obj = e.Current;
            if (obj is DerObjectIdentifier)
            {
                semanticsIdentifier = DerObjectIdentifier.GetInstance(obj);
                if (e.MoveNext())
                {
                    obj  = e.Current;
                }
                else
                {
                    obj  = null;
                }
            }

			if (obj  != null)
            {
                Asn1Sequence generalNameSeq = Asn1Sequence.GetInstance(obj );
                nameRegistrationAuthorities = new GeneralName[generalNameSeq.Count];
                for (int i= 0; i < generalNameSeq.Count; i++)
                {
                    nameRegistrationAuthorities[i] = GeneralName.GetInstance(generalNameSeq[i]);
                }
            }
        }
		/**
		* Constructor from Asn1Sequence.
		* <p/>
		* <p/>
		* <pre>
		*             NamingAuthority ::= SEQUENCE
		*             {
		*               namingAuthorityID OBJECT IDENTIFIER OPTIONAL,
		*               namingAuthorityUrl IA5String OPTIONAL,
		*               namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
		*             }
		* </pre>
		*
		* @param seq The ASN.1 sequence.
		*/
		private NamingAuthority(
			Asn1Sequence seq)
		{
			if (seq.Count > 3)
				throw new ArgumentException("Bad sequence size: " + seq.Count);

			IEnumerator e = seq.GetEnumerator();

			if (e.MoveNext())
			{
				Asn1Encodable o = (Asn1Encodable) e.Current;
				if (o is DerObjectIdentifier)
				{
					namingAuthorityID = (DerObjectIdentifier) o;
				}
				else if (o is DerIA5String)
				{
					namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
				}
				else if (o is IAsn1String)
				{
					namingAuthorityText = DirectoryString.GetInstance(o);
				}
				else
				{
					throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
				}
			}

			if (e.MoveNext())
			{
				Asn1Encodable o = (Asn1Encodable) e.Current;
				if (o is DerIA5String)
				{
					namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
				}
				else if (o is IAsn1String)
				{
					namingAuthorityText = DirectoryString.GetInstance(o);
				}
				else
				{
					throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
				}
			}

			if (e.MoveNext())
			{
				Asn1Encodable o = (Asn1Encodable) e.Current;
				if (o is IAsn1String)
				{
					namingAuthorityText = DirectoryString.GetInstance(o);
				}
				else
				{
					throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
				}
			}
		}
Esempio n. 4
0
		public KeySpecificInfo(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

			e.MoveNext();
            algorithm = (DerObjectIdentifier)e.Current;
            e.MoveNext();
            counter = (Asn1OctetString)e.Current;
        }
Esempio n. 5
0
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * The sequence is of type ProcurationSyntax:
         * <p/>
         * <pre>
         *            Admissions ::= SEQUENCE
         *            {
         *              admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
         *              namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
         *              professionInfos SEQUENCE OF ProfessionInfo
         *            }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private Admissions(
            Asn1Sequence seq)
        {
            if (seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            Asn1Encodable o = (Asn1Encodable)e.Current;

            if (o is Asn1TaggedObject)
            {
                switch (((Asn1TaggedObject)o).TagNo)
                {
                case 0:
                    admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true);
                    break;

                case 1:
                    namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
                    break;

                default:
                    throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
                }
                e.MoveNext();
                o = (Asn1Encodable)e.Current;
            }
            if (o is Asn1TaggedObject)
            {
                switch (((Asn1TaggedObject)o).TagNo)
                {
                case 1:
                    namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
                    break;

                default:
                    throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
                }
                e.MoveNext();
                o = (Asn1Encodable)e.Current;
            }
            professionInfos = Asn1Sequence.GetInstance(o);
            if (e.MoveNext())
            {
                throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(e.Current));
            }
        }
        private PrivateKeyInfo(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            this.version = DerInteger.GetInstance(CollectionUtilities.RequireNext(e));

            int versionValue = GetVersionValue(version);

            this.privateKeyAlgorithm = AlgorithmIdentifier.GetInstance(CollectionUtilities.RequireNext(e));
            this.privateKey          = Asn1OctetString.GetInstance(CollectionUtilities.RequireNext(e));

            int lastTag = -1;

            while (e.MoveNext())
            {
                Asn1TaggedObject tagged = (Asn1TaggedObject)e.Current;

                int tag = tagged.TagNo;
                if (tag <= lastTag)
                {
                    throw new ArgumentException("invalid optional field in private key info", "seq");
                }

                lastTag = tag;

                switch (tag)
                {
                case 0:
                {
                    this.attributes = Asn1Set.GetInstance(tagged, false);
                    break;
                }

                case 1:
                {
                    if (versionValue < 1)
                    {
                        throw new ArgumentException("'publicKey' requires version v2(1) or later", "seq");
                    }

                    this.publicKey = DerBitString.GetInstance(tagged, false);
                    break;
                }

                default:
                {
                    throw new ArgumentException("unknown optional field in private key info", "seq");
                }
                }
            }
        }
Esempio n. 7
0
        public TbsSign(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            Version      = DerInteger.GetInstance(e.Next());
            EsSeal       = SeSeal.GetInstance(e.Next());
            TimeInfo     = DerGeneralizedTime.GetInstance(e.Next());
            DataHash     = DerBitString.GetInstance(e.Next());
            PropertyInfo = DerIA5String.GetInstance(e.Next());
            if (e.MoveNext())
            {
                ExtData = ExtensionData.GetInstance(e.Current);
            }
        }
Esempio n. 8
0
        public TbsSign(Asn1Sequence seq)
        {
            var e = seq.GetEnumerator();

            Version      = DerInteger.GetInstance(e.Next());
            EsSeal       = SesSealInfo.GetInstance(e.Next());
            TimeInfo     = DerBitString.GetInstance(e.Next());
            DataHash     = DerBitString.GetInstance(e.Next());
            PropertyInfo = DerIA5String.GetInstance(e.Next());
            if (e.MoveNext())
            {
                ExtensionData = ExtensionData.GetInstance(e.Next());
            }
        }
Esempio n. 9
0
        private X500Name(
            IX500NameStyle style,
            Asn1Sequence seq)
        {
            this.style = style;
            this.rdns  = new Rdn[seq.Count];

            int index = 0;

            for (IEnumerator e = seq.GetEnumerator(); e.MoveNext();)
            {
                rdns[index++] = Rdn.GetInstance(e.Current);
            }
        }
Esempio n. 10
0
        private SignedData(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            version = (DerInteger)e.Current;

            e.MoveNext();
            digestAlgorithms = ((Asn1Set)e.Current);

            e.MoveNext();
            contentInfo = ContentInfo.GetInstance(e.Current);

            while (e.MoveNext())
            {
                Asn1Object o = (Asn1Object)e.Current;

                //
                // an interesting feature of SignedData is that there appear
                // to be varying implementations...
                // for the moment we ignore anything which doesn't fit.
                //
                if (o is Asn1TaggedObject)
                {
                    Asn1TaggedObject tagged = (Asn1TaggedObject)o;

                    switch (tagged.TagNo)
                    {
                    case 0:
                        certsBer     = tagged is BerTaggedObject;
                        certificates = Asn1Set.GetInstance(tagged, false);
                        break;

                    case 1:
                        crlsBer = tagged is BerTaggedObject;
                        crls    = Asn1Set.GetInstance(tagged, false);
                        break;

                    default:
                        throw new ArgumentException("unknown tag value " + tagged.TagNo);
                    }
                }
                else
                {
                    signerInfos = (Asn1Set)o;
                }
            }
        }
Esempio n. 11
0
    private TstInfo(Asn1Sequence seq)
    {
        IEnumerator enumerator = seq.GetEnumerator();

        enumerator.MoveNext();
        version = DerInteger.GetInstance(enumerator.Current);
        enumerator.MoveNext();
        tsaPolicyId = DerObjectIdentifier.GetInstance(enumerator.Current);
        enumerator.MoveNext();
        messageImprint = MessageImprint.GetInstance(enumerator.Current);
        enumerator.MoveNext();
        serialNumber = DerInteger.GetInstance(enumerator.Current);
        enumerator.MoveNext();
        genTime  = DerGeneralizedTime.GetInstance(enumerator.Current);
        ordering = DerBoolean.False;
        while (enumerator.MoveNext())
        {
            Asn1Object asn1Object = (Asn1Object)enumerator.Current;
            if (asn1Object is Asn1TaggedObject)
            {
                DerTaggedObject derTaggedObject = (DerTaggedObject)asn1Object;
                switch (derTaggedObject.TagNo)
                {
                case 0:
                    tsa = GeneralName.GetInstance(derTaggedObject, explicitly: true);
                    break;

                case 1:
                    extensions = X509Extensions.GetInstance(derTaggedObject, explicitly: false);
                    break;

                default:
                    throw new ArgumentException("Unknown tag value " + derTaggedObject.TagNo);
                }
            }
            if (asn1Object is DerSequence)
            {
                accuracy = Accuracy.GetInstance(asn1Object);
            }
            if (asn1Object is DerBoolean)
            {
                ordering = DerBoolean.GetInstance(asn1Object);
            }
            if (asn1Object is DerInteger)
            {
                nonce = DerInteger.GetInstance(asn1Object);
            }
        }
    }
Esempio n. 12
0
        private Admissions(Asn1Sequence seq)
        {
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            //IL_00aa: Unknown result type (might be due to invalid IL or missing references)
            //IL_0109: Unknown result type (might be due to invalid IL or missing references)
            //IL_014b: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count > 3)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current();

            if (asn1Encodable is Asn1TaggedObject)
            {
                switch (((Asn1TaggedObject)asn1Encodable).TagNo)
                {
                case 0:
                    admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)asn1Encodable, explicitly: true);
                    break;

                case 1:
                    namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)asn1Encodable, isExplicit: true);
                    break;

                default:
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)((Asn1TaggedObject)asn1Encodable).TagNo));
                }
                enumerator.MoveNext();
                asn1Encodable = (Asn1Encodable)enumerator.get_Current();
            }
            if (asn1Encodable is Asn1TaggedObject)
            {
                int tagNo = ((Asn1TaggedObject)asn1Encodable).TagNo;
                if (tagNo != 1)
                {
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)((Asn1TaggedObject)asn1Encodable).TagNo));
                }
                namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)asn1Encodable, isExplicit: true);
                enumerator.MoveNext();
                asn1Encodable = (Asn1Encodable)enumerator.get_Current();
            }
            professionInfos = Asn1Sequence.GetInstance(asn1Encodable);
            if (enumerator.MoveNext())
            {
                throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(enumerator.get_Current()));
            }
        }
Esempio n. 13
0
        private TstInfo(Asn1Sequence seq)
        {
            //IL_00fa: Unknown result type (might be due to invalid IL or missing references)
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            version = DerInteger.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            tsaPolicyId = DerObjectIdentifier.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            messageImprint = MessageImprint.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            serialNumber = DerInteger.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            genTime  = DerGeneralizedTime.GetInstance(enumerator.get_Current());
            ordering = DerBoolean.False;
            while (enumerator.MoveNext())
            {
                Asn1Object asn1Object = (Asn1Object)enumerator.get_Current();
                if (asn1Object is Asn1TaggedObject)
                {
                    DerTaggedObject derTaggedObject = (DerTaggedObject)asn1Object;
                    switch (derTaggedObject.TagNo)
                    {
                    case 0:
                        tsa = GeneralName.GetInstance(derTaggedObject, explicitly: true);
                        break;

                    case 1:
                        extensions = X509Extensions.GetInstance(derTaggedObject, explicitly: false);
                        break;

                    default:
                        throw new ArgumentException(string.Concat((object)"Unknown tag value ", (object)derTaggedObject.TagNo));
                    }
                }
                if (asn1Object is DerSequence)
                {
                    accuracy = Accuracy.GetInstance(asn1Object);
                }
                if (asn1Object is DerBoolean)
                {
                    ordering = DerBoolean.GetInstance(asn1Object);
                }
                if (asn1Object is DerInteger)
                {
                    nonce = DerInteger.GetInstance(asn1Object);
                }
            }
        }
Esempio n. 14
0
        public DHParameter(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            p = (DerInteger)e.Current;

            e.MoveNext();
            g = (DerInteger)e.Current;

            if (e.MoveNext())
            {
                l = (DerInteger)e.Current;
            }
        }
Esempio n. 15
0
        protected X509Name(Asn1Sequence seq)
        {
            this.ordering = Platform.CreateArrayList();
            this.values   = Platform.CreateArrayList();
            this.added    = Platform.CreateArrayList();
            this.seq      = seq;
            IEnumerator enumerator = seq.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Asn1Set instance = Asn1Set.GetInstance(((Asn1Encodable)enumerator.Current).ToAsn1Object());
                    for (int i = 0; i < instance.Count; i++)
                    {
                        Asn1Sequence sequence = Asn1Sequence.GetInstance(instance[i].ToAsn1Object());
                        if (sequence.Count != 2)
                        {
                            throw new ArgumentException("badly sized pair");
                        }
                        this.ordering.Add(DerObjectIdentifier.GetInstance(sequence[0].ToAsn1Object()));
                        Asn1Object obj2 = sequence[1].ToAsn1Object();
                        if ((obj2 is IAsn1String) && !(obj2 is DerUniversalString))
                        {
                            string source = ((IAsn1String)obj2).GetString();
                            if (Platform.StartsWith(source, "#"))
                            {
                                source = @"\" + source;
                            }
                            this.values.Add(source);
                        }
                        else
                        {
                            this.values.Add("#" + Hex.ToHexString(obj2.GetEncoded()));
                        }
                        this.added.Add(i != 0);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable disposable)
                {
                    IDisposable disposable;
                    disposable.Dispose();
                }
            }
        }
        public Pbkdf2Params(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            octStr = (Asn1OctetString)e.Current;

            e.MoveNext();
            iterationCount = (DerInteger)e.Current;

            if (e.MoveNext())
            {
                keyLength = (DerInteger)e.Current;
            }
        }
        private ISet <DerObjectIdentifier> toSet(Asn1Sequence seq)
        {
            if (seq != null)
            {
                ISet <DerObjectIdentifier> oids = new HashSet <DerObjectIdentifier>();

                for (IEnumerator en = seq.GetEnumerator(); en.MoveNext();)
                {
                    oids.Add(DerObjectIdentifier.GetInstance(en.Current));
                }

                return(oids);
            }

            return(new HashSet <DerObjectIdentifier>());
        }
Esempio n. 18
0
 protected X509Name(Asn1Sequence seq)
 {
     //IL_007b: Unknown result type (might be due to invalid IL or missing references)
     this.seq = seq;
     global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current();
             Asn1Set       instance      = Asn1Set.GetInstance(asn1Encodable.ToAsn1Object());
             for (int i = 0; i < instance.Count; i++)
             {
                 Asn1Sequence instance2 = Asn1Sequence.GetInstance(instance[i].ToAsn1Object());
                 if (instance2.Count != 2)
                 {
                     throw new ArgumentException("badly sized pair");
                 }
                 ordering.Add((object)DerObjectIdentifier.GetInstance(instance2[0].ToAsn1Object()));
                 Asn1Object asn1Object = instance2[1].ToAsn1Object();
                 if (asn1Object is IAsn1String && !(asn1Object is DerUniversalString))
                 {
                     string text = ((IAsn1String)asn1Object).GetString();
                     if (Platform.StartsWith(text, "#"))
                     {
                         text = "\\" + text;
                     }
                     values.Add((object)text);
                 }
                 else
                 {
                     values.Add((object)("#" + Hex.ToHexString(asn1Object.GetEncoded())));
                 }
                 added.Add((object)(i != 0));
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
 }
Esempio n. 19
0
    private Admissions(Asn1Sequence seq)
    {
        if (seq.Count > 3)
        {
            throw new ArgumentException("Bad sequence size: " + seq.Count);
        }
        IEnumerator enumerator = seq.GetEnumerator();

        enumerator.MoveNext();
        Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.Current;

        if (asn1Encodable is Asn1TaggedObject)
        {
            switch (((Asn1TaggedObject)asn1Encodable).TagNo)
            {
            case 0:
                admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)asn1Encodable, explicitly: true);
                break;

            case 1:
                namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)asn1Encodable, isExplicit: true);
                break;

            default:
                throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)asn1Encodable).TagNo);
            }
            enumerator.MoveNext();
            asn1Encodable = (Asn1Encodable)enumerator.Current;
        }
        if (asn1Encodable is Asn1TaggedObject)
        {
            int tagNo = ((Asn1TaggedObject)asn1Encodable).TagNo;
            if (tagNo != 1)
            {
                throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)asn1Encodable).TagNo);
            }
            namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)asn1Encodable, isExplicit: true);
            enumerator.MoveNext();
            asn1Encodable = (Asn1Encodable)enumerator.Current;
        }
        professionInfos = Asn1Sequence.GetInstance(asn1Encodable);
        if (enumerator.MoveNext())
        {
            throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(enumerator.Current));
        }
    }
Esempio n. 20
0
        /**
        * Constructor from Asn1Sequence.
        * <p/>
        * The sequence is of type ProcurationSyntax:
        * <p/>
        * <pre>
        *            Admissions ::= SEQUENCE
        *            {
        *              admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
        *              namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
        *              professionInfos SEQUENCE OF ProfessionInfo
        *            }
        * </pre>
        *
        * @param seq The ASN.1 sequence.
        */
        private Admissions(
			Asn1Sequence seq)
        {
            if (seq.Count > 3)
                throw new ArgumentException("Bad sequence size: " + seq.Count);

            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            Asn1Encodable o = (Asn1Encodable) e.Current;
            if (o is Asn1TaggedObject)
            {
                switch (((Asn1TaggedObject)o).TagNo)
                {
                    case 0:
                        admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true);
                        break;
                    case 1:
                        namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
                        break;
                    default:
                        throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
                }
                e.MoveNext();
                o = (Asn1Encodable) e.Current;
            }
            if (o is Asn1TaggedObject)
            {
                switch (((Asn1TaggedObject)o).TagNo)
                {
                    case 1:
                        namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
                        break;
                    default:
                        throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
                }
                e.MoveNext();
                o = (Asn1Encodable) e.Current;
            }
            professionInfos = Asn1Sequence.GetInstance(o);
            if (e.MoveNext())
            {
                throw new ArgumentException("Bad object encountered: " + e.Current.GetType().Name);
            }
        }
Esempio n. 21
0
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * The sequence is of type NameOrPseudonym:
         * <p/>
         * <pre>
         *     PersonalData ::= SEQUENCE {
         *       nameOrPseudonym NameOrPseudonym,
         *       nameDistinguisher [0] INTEGER OPTIONAL,
         *       dateOfBirth [1] GeneralizedTime OPTIONAL,
         *       placeOfBirth [2] DirectoryString OPTIONAL,
         *       gender [3] PrintableString OPTIONAL,
         *       postalAddress [4] DirectoryString OPTIONAL
         *       }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private PersonalData(
            Asn1Sequence seq)
        {
            if (seq.Count < 1)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();

            nameOrPseudonym = NameOrPseudonym.GetInstance(e.Current);

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                int tag            = o.TagNo;
                switch (tag)
                {
                case 0:
                    nameDistinguisher = DerInteger.GetInstance(o, false).Value;
                    break;

                case 1:
                    dateOfBirth = DerGeneralizedTime.GetInstance(o, false);
                    break;

                case 2:
                    placeOfBirth = DirectoryString.GetInstance(o, true);
                    break;

                case 3:
                    gender = DerPrintableString.GetInstance(o, false).GetString();
                    break;

                case 4:
                    postalAddress = DirectoryString.GetInstance(o, true);
                    break;

                default:
                    throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
Esempio n. 22
0
        public SignerLocation(Asn1Sequence seq)
        {
            //IL_0086: Unknown result type (might be due to invalid IL or missing references)
            //IL_0091: Unknown result type (might be due to invalid IL or missing references)
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)enumerator.get_Current();
                    switch (asn1TaggedObject.TagNo)
                    {
                    case 0:
                        countryName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 1:
                        localityName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 2:
                    {
                        bool explicitly = asn1TaggedObject.IsExplicit();
                        postalAddress = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly);
                        if (postalAddress != null && postalAddress.Count > 6)
                        {
                            throw new ArgumentException("postal address must contain less than 6 strings");
                        }
                        break;
                    }

                    default:
                        throw new ArgumentException("illegal tag");
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Esempio n. 23
0
 public OtherInfo(Asn1Sequence seq)
 {
     global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
     enumerator.MoveNext();
     keyInfo = new KeySpecificInfo((Asn1Sequence)enumerator.get_Current());
     while (enumerator.MoveNext())
     {
         DerTaggedObject derTaggedObject = (DerTaggedObject)enumerator.get_Current();
         if (derTaggedObject.TagNo == 0)
         {
             partyAInfo = (Asn1OctetString)derTaggedObject.GetObject();
         }
         else if (derTaggedObject.TagNo == 2)
         {
             suppPubInfo = (Asn1OctetString)derTaggedObject.GetObject();
         }
     }
 }
Esempio n. 24
0
    public void IntersectPermittedSubtree(Asn1Sequence permitted)
    {
        IDictionary dictionary = Platform.CreateHashtable();
        IEnumerator enumerator = permitted.GetEnumerator();

        while (enumerator.MoveNext())
        {
            GeneralSubtree instance = GeneralSubtree.GetInstance(enumerator.Current);
            int            tagNo    = instance.Base.TagNo;
            if (dictionary[tagNo] == null)
            {
                dictionary[tagNo] = new HashSet();
            }
            ((ISet)dictionary[tagNo]).Add(instance);
        }
        IEnumerator enumerator2 = dictionary.GetEnumerator();

        while (enumerator2.MoveNext())
        {
            DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator2.Current;
            switch ((int)dictionaryEntry.Key)
            {
            case 1:
                permittedSubtreesEmail = IntersectEmail(permittedSubtreesEmail, (ISet)dictionaryEntry.Value);
                break;

            case 2:
                permittedSubtreesDNS = intersectDNS(permittedSubtreesDNS, (ISet)dictionaryEntry.Value);
                break;

            case 4:
                permittedSubtreesDN = IntersectDN(permittedSubtreesDN, (ISet)dictionaryEntry.Value);
                break;

            case 6:
                permittedSubtreesURI = intersectURI(permittedSubtreesURI, (ISet)dictionaryEntry.Value);
                break;

            case 7:
                permittedSubtreesIP = IntersectIP(permittedSubtreesIP, (ISet)dictionaryEntry.Value);
                break;
            }
        }
    }
Esempio n. 25
0
        private CrlOcspRef(Asn1Sequence seq)
        {
            //IL_000e: Unknown result type (might be due to invalid IL or missing references)
            //IL_007f: Unknown result type (might be due to invalid IL or missing references)
            if (seq == null)
            {
                throw new ArgumentNullException("seq");
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)enumerator.get_Current();
                    Asn1Object       @object          = asn1TaggedObject.GetObject();
                    switch (asn1TaggedObject.TagNo)
                    {
                    case 0:
                        crlids = CrlListID.GetInstance(@object);
                        break;

                    case 1:
                        ocspids = OcspListID.GetInstance(@object);
                        break;

                    case 2:
                        otherRev = OtherRevRefs.GetInstance(@object);
                        break;

                    default:
                        throw new ArgumentException("Illegal tag in CrlOcspRef", "seq");
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Esempio n. 26
0
        public OtherInfo(Asn1Sequence seq)
        {
            IEnumerator enumerator = seq.GetEnumerator();

            enumerator.MoveNext();
            this.keyInfo = new KeySpecificInfo((Asn1Sequence)enumerator.Current);
            while (enumerator.MoveNext())
            {
                DerTaggedObject derTaggedObject = (DerTaggedObject)enumerator.Current;
                if (derTaggedObject.TagNo == 0)
                {
                    this.partyAInfo = (Asn1OctetString)derTaggedObject.GetObject();
                }
                else if (derTaggedObject.TagNo == 2)
                {
                    this.suppPubInfo = (Asn1OctetString)derTaggedObject.GetObject();
                }
            }
        }
Esempio n. 27
0
        public SignerInfo(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            version = (DerInteger)e.Current;

            e.MoveNext();
            sid = SignerIdentifier.GetInstance(e.Current);

            e.MoveNext();
            digAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);

            e.MoveNext();
            object obj = e.Current;

            if (obj is Asn1TaggedObject)
            {
                authenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)obj, false);

                e.MoveNext();
                digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);
            }
            else
            {
                authenticatedAttributes = null;
                digEncryptionAlgorithm  = AlgorithmIdentifier.GetInstance(obj);
            }

            e.MoveNext();
            encryptedDigest = DerOctetString.GetInstance(e.Current);

            if (e.MoveNext())
            {
                unauthenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)e.Current, false);
            }
            else
            {
                unauthenticatedAttributes = null;
            }
        }
Esempio n. 28
0
		public SignerInfo(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

			e.MoveNext();
            version = (DerInteger) e.Current;

			e.MoveNext();
            issuerAndSerialNumber = IssuerAndSerialNumber.GetInstance(e.Current);

			e.MoveNext();
            digAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);

			e.MoveNext();
            object obj = e.Current;

			if (obj is Asn1TaggedObject)
            {
                authenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject) obj, false);

				e.MoveNext();
                digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);
            }
            else
            {
                authenticatedAttributes = null;
                digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(obj);
            }

			e.MoveNext();
            encryptedDigest = DerOctetString.GetInstance(e.Current);

			if (e.MoveNext())
            {
                unauthenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)e.Current, false);
            }
            else
            {
                unauthenticatedAttributes = null;
            }
        }
Esempio n. 29
0
        public PbeS2Parameters(
            Asn1Sequence obj)
        {
            IEnumerator e = obj.GetEnumerator();

            e.MoveNext();
            Asn1Sequence funcSeq = (Asn1Sequence) e.Current;

            if (funcSeq[0].Equals(PkcsObjectIdentifiers.IdPbkdf2))
            {
                func = new KeyDerivationFunc(PkcsObjectIdentifiers.IdPbkdf2, funcSeq[1]);
            }
            else
            {
                func = new KeyDerivationFunc(funcSeq);
            }

            e.MoveNext();
            scheme = new EncryptionScheme((Asn1Sequence) e.Current);
        }
Esempio n. 30
0
        private PrivateKeyInfo(Asn1Sequence seq)
        {
            //IL_0042: Unknown result type (might be due to invalid IL or missing references)
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            BigInteger value = ((DerInteger)enumerator.get_Current()).Value;

            if (value.IntValue != 0)
            {
                throw new ArgumentException(string.Concat((object)"wrong version for private key info: ", (object)value.IntValue));
            }
            enumerator.MoveNext();
            algID = AlgorithmIdentifier.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            privKey = Asn1OctetString.GetInstance(enumerator.get_Current());
            if (enumerator.MoveNext())
            {
                attributes = Asn1Set.GetInstance((Asn1TaggedObject)enumerator.get_Current(), explicitly: false);
            }
        }
    private PrivateKeyInfo(Asn1Sequence seq)
    {
        IEnumerator enumerator = seq.GetEnumerator();

        enumerator.MoveNext();
        BigInteger value = ((DerInteger)enumerator.Current).Value;

        if (value.IntValue != 0)
        {
            throw new ArgumentException("wrong version for private key info: " + value.IntValue);
        }
        enumerator.MoveNext();
        algID = AlgorithmIdentifier.GetInstance(enumerator.Current);
        enumerator.MoveNext();
        privKey = Asn1OctetString.GetInstance(enumerator.Current);
        if (enumerator.MoveNext())
        {
            attributes = Asn1Set.GetInstance((Asn1TaggedObject)enumerator.Current, explicitly: false);
        }
    }
Esempio n. 32
0
        public PbeS2Parameters(
            Asn1Sequence obj)
        {
            IEnumerator e = obj.GetEnumerator();

            e.MoveNext();
            Asn1Sequence funcSeq = (Asn1Sequence)e.Current;

            if (funcSeq[0].Equals(PkcsObjectIdentifiers.IdPbkdf2))
            {
                func = new KeyDerivationFunc(PkcsObjectIdentifiers.IdPbkdf2, funcSeq[1]);
            }
            else
            {
                func = new KeyDerivationFunc(funcSeq);
            }

            e.MoveNext();
            scheme = new EncryptionScheme((Asn1Sequence)e.Current);
        }
Esempio n. 33
0
        private global::System.Collections.IList GetCertList()
        {
            //IL_0046: Expected O, but got Unknown
            global::System.Collections.IList list = Platform.CreateArrayList();
            Asn1Sequence certs = resp.Certs;

            if (certs != null)
            {
                global::System.Collections.IEnumerator enumerator = certs.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current();
                        try
                        {
                            list.Add((object)new X509CertificateParser().ReadCertificate(asn1Encodable.GetEncoded()));
                        }
                        catch (IOException val)
                        {
                            IOException e = val;
                            throw new OcspException("can't re-encode certificate!", (global::System.Exception)(object) e);
                        }
                        catch (CertificateException e2)
                        {
                            throw new OcspException("can't re-encode certificate!", e2);
                        }
                    }
                    return(list);
                }
                finally
                {
                    global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            return(list);
        }
Esempio n. 34
0
        public static List <string> GetAuthorityInformationAccessOcspUrl(X509Certificate cert)
        {
            List <string> ocspUrls = new List <string>();

            try
            {
                Asn1Object obj = GetExtensionValue(cert, X509Extensions.AuthorityInfoAccess.Id);

                if (obj == null)
                {
                    return(null);
                }

                // For a strange reason I cannot acess the aia.AccessDescription[].
                // Hope it will be fixed in the next version (1.5).
                // AuthorityInformationAccess aia = AuthorityInformationAccess.GetInstance(obj);

                // Switched to manual parse
                Asn1Sequence s        = (Asn1Sequence)obj;
                IEnumerator  elements = s.GetEnumerator();

                while (elements.MoveNext())
                {
                    Asn1Sequence        element = (Asn1Sequence)elements.Current;
                    DerObjectIdentifier oid     = (DerObjectIdentifier)element[0];

                    if (oid.Id.Equals("1.3.6.1.5.5.7.48.1")) // Is Ocsp?
                    {
                        Asn1TaggedObject taggedObject = (Asn1TaggedObject)element[1];
                        GeneralName      gn           = (GeneralName)GeneralName.GetInstance(taggedObject);
                        ocspUrls.Add(((DerIA5String)DerIA5String.GetInstance(gn.Name)).GetString());
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error parsing AIA.", e);
            }

            return(ocspUrls);
        }
Esempio n. 35
0
        private ProcurationSyntax(Asn1Sequence seq)
        {
            //IL_002d: Unknown result type (might be due to invalid IL or missing references)
            //IL_00cb: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.get_Current());
                switch (instance.TagNo)
                {
                case 1:
                    country = DerPrintableString.GetInstance(instance, isExplicit: true).GetString();
                    break;

                case 2:
                    typeOfSubstitution = DirectoryString.GetInstance(instance, isExplicit: true);
                    break;

                case 3:
                {
                    Asn1Object @object = instance.GetObject();
                    if (@object is Asn1TaggedObject)
                    {
                        thirdPerson = GeneralName.GetInstance(@object);
                    }
                    else
                    {
                        certRef = IssuerSerial.GetInstance(@object);
                    }
                    break;
                }

                default:
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)instance.TagNo));
                }
            }
        }
Esempio n. 36
0
        private PersonalData(Asn1Sequence seq)
        {
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            //IL_00e9: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count < 1)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            nameOrPseudonym = NameOrPseudonym.GetInstance(enumerator.get_Current());
            while (enumerator.MoveNext())
            {
                Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.get_Current());
                switch (instance.TagNo)
                {
                case 0:
                    nameDistinguisher = DerInteger.GetInstance(instance, isExplicit: false).Value;
                    break;

                case 1:
                    dateOfBirth = DerGeneralizedTime.GetInstance(instance, isExplicit: false);
                    break;

                case 2:
                    placeOfBirth = DirectoryString.GetInstance(instance, isExplicit: true);
                    break;

                case 3:
                    gender = DerPrintableString.GetInstance(instance, isExplicit: false).GetString();
                    break;

                case 4:
                    postalAddress = DirectoryString.GetInstance(instance, isExplicit: true);
                    break;

                default:
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)instance.TagNo));
                }
            }
        }
        private PrivateKeyInfo(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            BigInteger version = ((DerInteger)e.Current).Value;
            if (version.IntValue != 0)
            {
                throw new ArgumentException("wrong version for private key info: " + version.IntValue);
            }

            e.MoveNext();
            algID = AlgorithmIdentifier.GetInstance(e.Current);
            e.MoveNext();
            privKey = Asn1OctetString.GetInstance(e.Current);

            if (e.MoveNext())
            {
                attributes = Asn1Set.GetInstance((Asn1TaggedObject)e.Current, false);
            }
        }
Esempio n. 38
0
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * The sequence is of type ProcurationSyntax:
         * <p/>
         * <pre>
         *               ProcurationSyntax ::= SEQUENCE {
         *                 country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
         *                 typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
         *                 signingFor [3] EXPLICIT SigningFor
         *               }
         * <p/>
         *               SigningFor ::= CHOICE
         *               {
         *                 thirdPerson GeneralName,
         *                 certRef IssuerSerial
         *               }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private ProcurationSyntax(
            Asn1Sequence seq)
        {
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                switch (o.TagNo)
                {
                case 1:
                    country = DerPrintableString.GetInstance(o, true).GetString();
                    break;

                case 2:
                    typeOfSubstitution = DirectoryString.GetInstance(o, true);
                    break;

                case 3:
                    Asn1Object signingFor = o.GetObject();
                    if (signingFor is Asn1TaggedObject)
                    {
                        thirdPerson = GeneralName.GetInstance(signingFor);
                    }
                    else
                    {
                        certRef = IssuerSerial.GetInstance(signingFor);
                    }
                    break;

                default:
                    throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
Esempio n. 39
0
		public OtherInfo(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

			e.MoveNext();
            keyInfo = new KeySpecificInfo((Asn1Sequence) e.Current);

			while (e.MoveNext())
            {
                DerTaggedObject o = (DerTaggedObject) e.Current;

				if (o.TagNo == 0)
                {
                    partyAInfo = (Asn1OctetString) o.GetObject();
                }
                else if ((int) o.TagNo == 2)
                {
                    suppPubInfo = (Asn1OctetString) o.GetObject();
                }
            }
        }
		private DHDomainParameters(Asn1Sequence seq)
		{
			if (seq.Count < 3 || seq.Count > 5)
				throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");

			IEnumerator e = seq.GetEnumerator();
			this.p = DerInteger.GetInstance(GetNext(e));
			this.g = DerInteger.GetInstance(GetNext(e));
			this.q = DerInteger.GetInstance(GetNext(e));

			Asn1Encodable next = GetNext(e);

			if (next != null && next is DerInteger)
			{
				this.j = DerInteger.GetInstance(next);
				next = GetNext(e);
			}

			if (next != null)
			{
				this.validationParms = DHValidationParms.GetInstance(next.ToAsn1Object());
			}
		}
Esempio n. 41
0
		/**
		* Constructor from Asn1Sequence.
		* <p/>
		* The sequence is of type NameOrPseudonym:
		* <p/>
		* <pre>
		*     PersonalData ::= SEQUENCE {
		*       nameOrPseudonym NameOrPseudonym,
		*       nameDistinguisher [0] INTEGER OPTIONAL,
		*       dateOfBirth [1] GeneralizedTime OPTIONAL,
		*       placeOfBirth [2] DirectoryString OPTIONAL,
		*       gender [3] PrintableString OPTIONAL,
		*       postalAddress [4] DirectoryString OPTIONAL
		*       }
		* </pre>
		*
		* @param seq The ASN.1 sequence.
		*/
		private PersonalData(
			Asn1Sequence seq)
		{
			if (seq.Count < 1)
				throw new ArgumentException("Bad sequence size: " + seq.Count);

			IEnumerator e = seq.GetEnumerator();
			e.MoveNext();

			nameOrPseudonym = NameOrPseudonym.GetInstance(e.Current);

			while (e.MoveNext())
			{
				Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
				int tag = o.TagNo;
				switch (tag)
				{
					case 0:
						nameDistinguisher = DerInteger.GetInstance(o, false).Value;
						break;
					case 1:
						dateOfBirth = DerGeneralizedTime.GetInstance(o, false);
						break;
					case 2:
						placeOfBirth = DirectoryString.GetInstance(o, true);
						break;
					case 3:
						gender = DerPrintableString.GetInstance(o, false).GetString();
						break;
					case 4:
						postalAddress = DirectoryString.GetInstance(o, true);
						break;
					default:
						throw new ArgumentException("Bad tag number: " + o.TagNo);
				}
			}
		}
Esempio n. 42
0
		private TstInfo(
			Asn1Sequence seq)
		{
			IEnumerator e = seq.GetEnumerator();

			// version
			e.MoveNext();
			version = DerInteger.GetInstance(e.Current);

			// tsaPolicy
			e.MoveNext();
			tsaPolicyId = DerObjectIdentifier.GetInstance(e.Current);

			// messageImprint
			e.MoveNext();
			messageImprint = MessageImprint.GetInstance(e.Current);

			// serialNumber
			e.MoveNext();
			serialNumber = DerInteger.GetInstance(e.Current);

			// genTime
			e.MoveNext();
			genTime = DerGeneralizedTime.GetInstance(e.Current);

			// default for ordering
			ordering = DerBoolean.False;

			while (e.MoveNext())
			{
				Asn1Object o = (Asn1Object) e.Current;

				if (o is Asn1TaggedObject)
				{
					DerTaggedObject tagged = (DerTaggedObject) o;

					switch (tagged.TagNo)
					{
						case 0:
							tsa = GeneralName.GetInstance(tagged, true);
							break;
						case 1:
							extensions = X509Extensions.GetInstance(tagged, false);
							break;
						default:
							throw new ArgumentException("Unknown tag value " + tagged.TagNo);
					}
				}

				if (o is DerSequence)
				{
					accuracy = Accuracy.GetInstance(o);
				}

				if (o is DerBoolean)
				{
					ordering = DerBoolean.GetInstance(o);
				}

				if (o is DerInteger)
				{
					nonce = DerInteger.GetInstance(o);
				}
			}
		}
Esempio n. 43
0
        /**
        * Constructor from Asn1Sequence.
        * <p/>
        * The sequence is of type ProcurationSyntax:
        * <p/>
        * <pre>
        *               ProcurationSyntax ::= SEQUENCE {
        *                 country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
        *                 typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
        *                 signingFor [3] EXPLICIT SigningFor
        *               }
        * <p/>
        *               SigningFor ::= CHOICE
        *               {
        *                 thirdPerson GeneralName,
        *                 certRef IssuerSerial
        *               }
        * </pre>
        *
        * @param seq The ASN.1 sequence.
        */
        private Procuration(
			Asn1Sequence seq)
        {
            if (seq.Count < 1 || seq.Count > 3)
                throw new ArgumentException("Bad sequence size: " + seq.Count);

            IEnumerator e = seq.GetEnumerator();

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                switch (o.TagNo)
                {
                    case 1:
                        country = DerPrintableString.GetInstance(o, true);
                        break;
                    case 2:
                        typeOfSubstitution = DirectoryString.GetInstance(o, true);
                        break;
                    case 3:
                        Asn1Object signingFor = o.GetObject();
                        if (signingFor is Asn1TaggedObject)
                        {
                            thirdPerson = GeneralName.GetInstance(signingFor);
                        }
                        else
                        {
                            certRef = IssuerSerial.GetInstance(signingFor);
                        }
                        break;
                    default:
                        throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
Esempio n. 44
0
        private SignedData(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            version = (DerInteger)e.Current;

            e.MoveNext();
            digestAlgorithms = ((Asn1Set)e.Current);

            e.MoveNext();
            contentInfo = ContentInfo.GetInstance(e.Current);

            while (e.MoveNext())
            {
                Asn1Object o = (Asn1Object)e.Current;

                //
                // an interesting feature of SignedData is that there appear
                // to be varying implementations...
                // for the moment we ignore anything which doesn't fit.
                //
                if (o is Asn1TaggedObject)
                {
                    Asn1TaggedObject tagged = (Asn1TaggedObject)o;

                    switch (tagged.TagNo)
                    {
                        case 0:
                            certsBer = tagged is BerTaggedObject;
                            certificates = Asn1Set.GetInstance(tagged, false);
                            break;
                        case 1:
                            crlsBer = tagged is BerTaggedObject;
                            crls = Asn1Set.GetInstance(tagged, false);
                            break;
                        default:
                            throw new ArgumentException("unknown tag value " + tagged.TagNo);
                    }
                }
                else
                {
                    signerInfos = (Asn1Set) o;
                }
            }
        }
Esempio n. 45
0
		/**
		* Constructor from Asn1Sequence.
		* <p/>
		* <p/>
		* <pre>
		*               ProfessionInfo ::= SEQUENCE
		*               {
		*                 namingAuthority [0] EXPLICIT NamingAuthority OPTIONAL,
		*                 professionItems SEQUENCE OF DirectoryString (SIZE(1..128)),
		*                 professionOids SEQUENCE OF OBJECT IDENTIFIER OPTIONAL,
		*                 registrationNumber PrintableString(SIZE(1..128)) OPTIONAL,
		*                 addProfessionInfo OCTET STRING OPTIONAL
		*               }
		* </pre>
		*
		* @param seq The ASN.1 sequence.
		*/
		private ProfessionInfo(
			Asn1Sequence seq)
		{
			if (seq.Count > 5)
				throw new ArgumentException("Bad sequence size: " + seq.Count);

			IEnumerator e = seq.GetEnumerator();

			e.MoveNext();
			Asn1Encodable o = (Asn1Encodable) e.Current;

			if (o is Asn1TaggedObject)
			{
				Asn1TaggedObject ato = (Asn1TaggedObject) o;
				if (ato.TagNo != 0)
					throw new ArgumentException("Bad tag number: " + ato.TagNo);

				namingAuthority = NamingAuthority.GetInstance(ato, true);
				e.MoveNext();
				o = (Asn1Encodable) e.Current;
			}

			professionItems = Asn1Sequence.GetInstance(o);

			if (e.MoveNext())
			{
				o = (Asn1Encodable) e.Current;
				if (o is Asn1Sequence)
				{
					professionOids = Asn1Sequence.GetInstance(o);
				}
				else if (o is DerPrintableString)
				{
					registrationNumber = DerPrintableString.GetInstance(o).GetString();
				}
				else if (o is Asn1OctetString)
				{
					addProfessionInfo = Asn1OctetString.GetInstance(o);
				}
				else
				{
					throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
				}
			}

			if (e.MoveNext())
			{
				o = (Asn1Encodable) e.Current;
				if (o is DerPrintableString)
				{
					registrationNumber = DerPrintableString.GetInstance(o).GetString();
				}
				else if (o is DerOctetString)
				{
					addProfessionInfo = (DerOctetString) o;
				}
				else
				{
					throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
				}
			}

			if (e.MoveNext())
			{
				o = (Asn1Encodable) e.Current;
				if (o is DerOctetString)
				{
					addProfessionInfo = (DerOctetString) o;
				}
				else
				{
					throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
				}
			}
		}