예제 #1
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: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(e.Current));
            }
        }
예제 #2
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: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
                }
            }

            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: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
                }
            }

            if (e.MoveNext())
            {
                o = (Asn1Encodable)e.Current;
                if (o is DerOctetString)
                {
                    addProfessionInfo = (DerOctetString)o;
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
                }
            }
        }