Inheritance: LimitedInputStream
Beispiel #1
0
        private Asn1Object BuildObject(int tag, int tagNo, int length)
        {
            bool isConstructed = (tag & 0x20) != 0;
            DefiniteLengthInputStream inStream = new DefiniteLengthInputStream(base.s, length);

            if ((tag & 0x40) != 0)
            {
                return(new DerApplicationSpecific(isConstructed, tagNo, inStream.ToArray()));
            }
            if ((tag & 0x80) != 0)
            {
                return(new Asn1StreamParser(inStream).ReadTaggedObject(isConstructed, tagNo));
            }
            if (!isConstructed)
            {
                return(CreatePrimitiveDerObject(tagNo, inStream, this.tmpBuffers));
            }
            if (tagNo == 0x10)
            {
                return(this.CreateDerSequence(inStream));
            }
            if (tagNo == 0x11)
            {
                return(this.CreateDerSet(inStream));
            }
            if (tagNo != 4)
            {
                if (tagNo != 8)
                {
                    throw new IOException("unknown tag " + tagNo + " encountered");
                }
                return(new DerExternal(this.BuildDerEncodableVector(inStream)));
            }
            return(new BerOctetString(this.BuildDerEncodableVector(inStream)));
        }
Beispiel #2
0
        internal Asn1Object ReadTaggedObject(bool constructed, int tag)
        {
            if (!constructed)
            {
                DefiniteLengthInputStream definiteLengthInputStream = (DefiniteLengthInputStream)this._in;
                return(new DerTaggedObject(false, tag, new DerOctetString(definiteLengthInputStream.ToArray())));
            }
            Asn1EncodableVector asn1EncodableVector = this.ReadVector();

            if (this._in is IndefiniteLengthInputStream)
            {
                if (asn1EncodableVector.Count != 1)
                {
                    return(new BerTaggedObject(false, tag, BerSequence.FromVector(asn1EncodableVector)));
                }
                return(new BerTaggedObject(true, tag, asn1EncodableVector[0]));
            }
            else
            {
                if (asn1EncodableVector.Count != 1)
                {
                    return(new DerTaggedObject(false, tag, DerSequence.FromVector(asn1EncodableVector)));
                }
                return(new DerTaggedObject(true, tag, asn1EncodableVector[0]));
            }
        }
        public Asn1Object ToAsn1Object()
        {
            if (_indefiniteLength)
            {
                Asn1EncodableVector v = rLoadVector(_contentStream);

                return(v.Count == 1
                                        ?       new BerTaggedObject(true, _tagNumber, v[0])
                                        :       new BerTaggedObject(false, _tagNumber, BerSequence.FromVector(v)));
            }

            if (IsConstructed)
            {
                Asn1EncodableVector v = rLoadVector(_contentStream);

                return(v.Count == 1
                                        ?       new DerTaggedObject(true, _tagNumber, v[0])
                                        :       new DerTaggedObject(false, _tagNumber, DerSequence.FromVector(v)));
            }

            try
            {
                DefiniteLengthInputStream defIn = (DefiniteLengthInputStream)_contentStream;
                return(new DerTaggedObject(false, _tagNumber, new DerOctetString(defIn.ToArray())));
            }
            catch (IOException e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }
        private Asn1Object BuildObject(int tag, int tagNo, int length)
        {
            bool flag = (tag & 0x20) != 0;
            DefiniteLengthInputStream definiteLengthInputStream = new DefiniteLengthInputStream(s, length);

            if ((tag & 0x40) != 0)
            {
                return(new DerApplicationSpecific(flag, tagNo, definiteLengthInputStream.ToArray()));
            }
            if ((tag & 0x80) != 0)
            {
                return(new Asn1StreamParser(definiteLengthInputStream).ReadTaggedObject(flag, tagNo));
            }
            if (flag)
            {
                switch (tagNo)
                {
                case 4:
                    return(new BerOctetString(BuildDerEncodableVector(definiteLengthInputStream)));

                case 16:
                    return(CreateDerSequence(definiteLengthInputStream));

                case 17:
                    return(CreateDerSet(definiteLengthInputStream));

                case 8:
                    return(new DerExternal(BuildDerEncodableVector(definiteLengthInputStream)));

                default:
                    throw new IOException("unknown tag " + tagNo + " encountered");
                }
            }
            return(CreatePrimitiveDerObject(tagNo, definiteLengthInputStream, tmpBuffers));
        }
Beispiel #5
0
        private static char[] GetBmpCharBuffer(DefiniteLengthInputStream defIn)
        {
            int remainingBytes = defIn.Remaining;

            if (0 != (remainingBytes & 1))
            {
                throw new IOException("malformed BMPString encoding encountered");
            }

            char[] str       = new char[remainingBytes / 2];
            int    stringPos = 0;

            byte[] buf = new byte[8];
            while (remainingBytes >= 8)
            {
                if (Streams.ReadFully(defIn, buf, 0, 8) != 8)
                {
                    throw new EndOfStreamException("EOF encountered in middle of BMPString");
                }

                str[stringPos]     = (char)((buf[0] << 8) | (buf[1] & 0xFF));
                str[stringPos + 1] = (char)((buf[2] << 8) | (buf[3] & 0xFF));
                str[stringPos + 2] = (char)((buf[4] << 8) | (buf[5] & 0xFF));
                str[stringPos + 3] = (char)((buf[6] << 8) | (buf[7] & 0xFF));
                stringPos         += 4;
                remainingBytes    -= 8;
            }
            if (remainingBytes > 0)
            {
                if (Streams.ReadFully(defIn, buf, 0, remainingBytes) != remainingBytes)
                {
                    throw new EndOfStreamException("EOF encountered in middle of BMPString");
                }

                int bufPos = 0;
                do
                {
                    int b1 = buf[bufPos++] << 8;
                    int b2 = buf[bufPos++] & 0xFF;
                    str[stringPos++] = (char)(b1 | b2);
                }while (bufPos < remainingBytes);
            }

            if (0 != defIn.Remaining || str.Length != stringPos)
            {
                throw new InvalidOperationException();
            }

            return(str);
        }
Beispiel #6
0
        internal static byte[] GetBuffer(DefiniteLengthInputStream defIn, byte[][] tmpBuffers)
        {
            int remaining = defIn.GetRemaining();

            if (remaining >= tmpBuffers.Length)
            {
                return(defIn.ToArray());
            }
            byte[] buf = tmpBuffers[remaining];
            if (buf == null)
            {
                buf = tmpBuffers[remaining] = new byte[remaining];
            }
            defIn.ReadAllIntoByteArray(buf);
            return(buf);
        }
Beispiel #7
0
        /**
         * build an object given its tag and the number of bytes to construct it from.
         */
        private Asn1Object BuildObject(
            int tag,
            int tagNo,
            int length)
        {
            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;

            DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(this.s, length);

            if ((tag & Asn1Tags.Application) != 0)
            {
                return(new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray()));
            }

            if ((tag & Asn1Tags.Tagged) != 0)
            {
                return(new Asn1StreamParser(defIn).ReadTaggedObject(isConstructed, tagNo));
            }

            if (isConstructed)
            {
                // TODO There are other tags that may be constructed (e.g. BitString)
                switch (tagNo)
                {
                case Asn1Tags.OctetString:
                    //
                    // yes, people actually do this...
                    //
                    return(new BerOctetString(BuildDerEncodableVector(defIn)));

                case Asn1Tags.Sequence:
                    return(CreateDerSequence(defIn));

                case Asn1Tags.Set:
                    return(CreateDerSet(defIn));

                case Asn1Tags.External:
                    return(new DerExternal(BuildDerEncodableVector(defIn)));

                default:
                    throw new IOException("unknown tag " + tagNo + " encountered");
                }
            }

            return(CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers));
        }
Beispiel #8
0
        internal virtual Asn1EncodableVector ReadVector(DefiniteLengthInputStream dIn)
        {
            if (dIn.Remaining < 1)
            {
                return(new Asn1EncodableVector(0));
            }

            Asn1InputStream     subStream = new Asn1InputStream(dIn);
            Asn1EncodableVector v         = new Asn1EncodableVector();
            Asn1Object          o;

            while ((o = subStream.ReadObject()) != null)
            {
                v.Add(o);
            }

            return(v);
        }
Beispiel #9
0
        private static byte[] GetBuffer(DefiniteLengthInputStream defIn, byte[][] tmpBuffers)
        {
            int len = defIn.Remaining;

            if (len >= tmpBuffers.Length)
            {
                return(defIn.ToArray());
            }

            byte[] buf = tmpBuffers[len];
            if (buf == null)
            {
                buf = tmpBuffers[len] = new byte[len];
            }

            defIn.ReadAllIntoByteArray(buf);

            return(buf);
        }
        /**
        * build an object given its tag and the number of bytes to construct it from.
        */
        private Asn1Object BuildObject(
            int	tag,
            int	tagNo,
            int	length)
        {
            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;

            DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(this.s, length);

            if ((tag & Asn1Tags.Application) != 0)
            {
                return new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray());
            }

            if ((tag & Asn1Tags.Tagged) != 0)
            {
                return new Asn1StreamParser(defIn).ReadTaggedObject(isConstructed, tagNo);
            }

            if (isConstructed)
            {
                // TODO There are other tags that may be constructed (e.g. BitString)
                switch (tagNo)
                {
                    case Asn1Tags.OctetString:
                        //
                        // yes, people actually do this...
                        //
                        return new BerOctetString(BuildDerEncodableVector(defIn));
                    case Asn1Tags.Sequence:
                        return CreateDerSequence(defIn);
                    case Asn1Tags.Set:
                        return CreateDerSet(defIn);
                    case Asn1Tags.External:
                        return new DerExternal(BuildDerEncodableVector(defIn));                
                    default:
                        throw new IOException("unknown tag " + tagNo + " encountered");
                }
            }

            return CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);
        }
Beispiel #11
0
        internal Asn1Object ReadTaggedObject(bool constructed, int tag)
        {
            if (!constructed)
            {
                // Note: !CONSTRUCTED => IMPLICIT
                DefiniteLengthInputStream defIn = (DefiniteLengthInputStream)_in;
                return(new DerTaggedObject(false, tag, new DerOctetString(defIn.ToArray())));
            }

            Asn1EncodableVector v = ReadVector();

            if (_in is IndefiniteLengthInputStream)
            {
                return(v.Count == 1
                                        ?   new BerTaggedObject(true, tag, v[0])
                                        :   new BerTaggedObject(false, tag, BerSequence.FromVector(v)));
            }

            return(v.Count == 1
                                ?   new DerTaggedObject(true, tag, v[0])
                                :   new DerTaggedObject(false, tag, DerSequence.FromVector(v)));
        }
Beispiel #12
0
        }        //IL_0003: Unknown result type (might be due to invalid IL or missing references)

        //IL_0010: Expected O, but got Unknown


        private Asn1Object BuildObject(int tag, int tagNo, int length)
        {
            //IL_00a2: Unknown result type (might be due to invalid IL or missing references)
            bool flag = (tag & 0x20) != 0;
            DefiniteLengthInputStream definiteLengthInputStream = new DefiniteLengthInputStream(s, length);

            if (((uint)tag & 0x40u) != 0)
            {
                return(new DerApplicationSpecific(flag, tagNo, definiteLengthInputStream.ToArray()));
            }
            if (((uint)tag & 0x80u) != 0)
            {
                return(new Asn1StreamParser((Stream)(object)definiteLengthInputStream).ReadTaggedObject(flag, tagNo));
            }
            if (flag)
            {
                switch (tagNo)
                {
                case 4:
                    return(new BerOctetString(BuildDerEncodableVector(definiteLengthInputStream)));

                case 16:
                    return(CreateDerSequence(definiteLengthInputStream));

                case 17:
                    return(CreateDerSet(definiteLengthInputStream));

                case 8:
                    return(new DerExternal(BuildDerEncodableVector(definiteLengthInputStream)));

                default:
                    throw new IOException(string.Concat((object)"unknown tag ", (object)tagNo, (object)" encountered"));
                }
            }
            return(CreatePrimitiveDerObject(tagNo, definiteLengthInputStream, tmpBuffers));
        }
        internal static Asn1Object CreatePrimitiveDerObject(
            int                         tagNo,
            DefiniteLengthInputStream   defIn,
            byte[][]                    tmpBuffers)
        {
            switch (tagNo)
            {
                case Asn1Tags.Boolean:
                    return DerBoolean.FromOctetString(GetBuffer(defIn, tmpBuffers));
                case Asn1Tags.Enumerated:
                    return DerEnumerated.FromOctetString(GetBuffer(defIn, tmpBuffers));
                case Asn1Tags.ObjectIdentifier:
                    return DerObjectIdentifier.FromOctetString(GetBuffer(defIn, tmpBuffers));
            }

            byte[] bytes = defIn.ToArray();

            switch (tagNo)
            {
                case Asn1Tags.BitString:
                    return DerBitString.FromAsn1Octets(bytes);
                case Asn1Tags.BmpString:
                    return new DerBmpString(bytes);
                case Asn1Tags.GeneralizedTime:
                    return new DerGeneralizedTime(bytes);
                case Asn1Tags.GeneralString:
                    return new DerGeneralString(bytes);
                case Asn1Tags.IA5String:
                    return new DerIA5String(bytes);
                case Asn1Tags.Integer:
                    return new DerInteger(bytes);
                case Asn1Tags.Null:
                    return DerNull.Instance;   // actual content is ignored (enforce 0 length?)
                case Asn1Tags.NumericString:
                    return new DerNumericString(bytes);
                case Asn1Tags.OctetString:
                    return new DerOctetString(bytes);
                case Asn1Tags.PrintableString:
                    return new DerPrintableString(bytes);
                case Asn1Tags.T61String:
                    return new DerT61String(bytes);
                case Asn1Tags.UniversalString:
                    return new DerUniversalString(bytes);
                case Asn1Tags.UtcTime:
                    return new DerUtcTime(bytes);
                case Asn1Tags.Utf8String:
                    return new DerUtf8String(bytes);
                case Asn1Tags.VisibleString:
                    return new DerVisibleString(bytes);
                default:
                    throw new IOException("unknown tag " + tagNo + " encountered");
            }
        }
		internal DerOctetStringParser(
			DefiniteLengthInputStream stream)
		{
			this.stream = stream;
		}
Beispiel #15
0
        internal static Asn1Object CreatePrimitiveDerObject(
            int tagNo,
            DefiniteLengthInputStream defIn,
            byte[][]                    tmpBuffers)
        {
            switch (tagNo)
            {
            case Asn1Tags.Boolean:
                return(DerBoolean.FromOctetString(GetBuffer(defIn, tmpBuffers)));

            case Asn1Tags.Enumerated:
                return(DerEnumerated.FromOctetString(GetBuffer(defIn, tmpBuffers)));

            case Asn1Tags.ObjectIdentifier:
                return(DerObjectIdentifier.FromOctetString(GetBuffer(defIn, tmpBuffers)));
            }

            byte[] bytes = defIn.ToArray();

            switch (tagNo)
            {
            case Asn1Tags.BitString:
                return(DerBitString.FromAsn1Octets(bytes));

            case Asn1Tags.BmpString:
                return(new DerBmpString(bytes));

            case Asn1Tags.GeneralizedTime:
                return(new DerGeneralizedTime(bytes));

            case Asn1Tags.GeneralString:
                return(new DerGeneralString(bytes));

            case Asn1Tags.IA5String:
                return(new DerIA5String(bytes));

            case Asn1Tags.Integer:
                return(new DerInteger(bytes));

            case Asn1Tags.Null:
                return(DerNull.Instance);      // actual content is ignored (enforce 0 length?)

            case Asn1Tags.NumericString:
                return(new DerNumericString(bytes));

            case Asn1Tags.OctetString:
                return(new DerOctetString(bytes));

            case Asn1Tags.PrintableString:
                return(new DerPrintableString(bytes));

            case Asn1Tags.T61String:
                return(new DerT61String(bytes));

            case Asn1Tags.UniversalString:
                return(new DerUniversalString(bytes));

            case Asn1Tags.UtcTime:
                return(new DerUtcTime(bytes));

            case Asn1Tags.Utf8String:
                return(new DerUtf8String(bytes));

            case Asn1Tags.VisibleString:
                return(new DerVisibleString(bytes));

            default:
                throw new IOException("unknown tag " + tagNo + " encountered");
            }
        }
Beispiel #16
0
        public virtual IAsn1Convertible ReadObject()
        {
            IAsn1Convertible convertible;
            int tag = this._in.ReadByte();

            if (tag == -1)
            {
                return(null);
            }
            this.Set00Check(false);
            int  num2          = Asn1InputStream.ReadTagNumber(this._in, tag);
            bool isConstructed = (tag & 0x20) != 0;
            int  length        = Asn1InputStream.ReadLength(this._in, this._limit);

            if (length < 0)
            {
                if (!isConstructed)
                {
                    throw new IOException("indefinite length primitive encoding encountered");
                }
                IndefiniteLengthInputStream stream = new IndefiniteLengthInputStream(this._in, this._limit);
                Asn1StreamParser            parser = new Asn1StreamParser(stream, this._limit);
                if ((tag & 0x40) != 0)
                {
                    return(new BerApplicationSpecificParser(num2, parser));
                }
                if ((tag & 0x80) != 0)
                {
                    return(new BerTaggedObjectParser(true, num2, parser));
                }
                return(parser.ReadIndef(num2));
            }
            DefiniteLengthInputStream inStream = new DefiniteLengthInputStream(this._in, length);

            if ((tag & 0x40) != 0)
            {
                return(new DerApplicationSpecific(isConstructed, num2, inStream.ToArray()));
            }
            if ((tag & 0x80) != 0)
            {
                return(new BerTaggedObjectParser(isConstructed, num2, new Asn1StreamParser(inStream)));
            }
            if (isConstructed)
            {
                switch (num2)
                {
                case 0x10:
                    return(new DerSequenceParser(new Asn1StreamParser(inStream)));

                case 0x11:
                    return(new DerSetParser(new Asn1StreamParser(inStream)));

                case 4:
                    return(new BerOctetStringParser(new Asn1StreamParser(inStream)));

                case 8:
                    return(new DerExternalParser(new Asn1StreamParser(inStream)));
                }
                throw new IOException("unknown tag " + num2 + " encountered");
            }
            if (num2 == 4)
            {
                return(new DerOctetStringParser(inStream));
            }
            try
            {
                convertible = Asn1InputStream.CreatePrimitiveDerObject(num2, inStream, this.tmpBuffers);
            }
            catch (ArgumentException exception)
            {
                throw new Asn1Exception("corrupted stream detected", exception);
            }
            return(convertible);
        }
Beispiel #17
0
		internal override DerSet CreateDerSet(
			DefiniteLengthInputStream dIn)
		{
			return new LazyDerSet(dIn.ToArray());
		}
Beispiel #18
0
 internal virtual DerSequence CreateDerSequence(
     DefiniteLengthInputStream dIn)
 {
     return(DerSequence.FromVector(BuildDerEncodableVector(dIn)));
 }
Beispiel #19
0
 internal DerOctetStringParser(
     DefiniteLengthInputStream stream)
 {
     this.stream = stream;
 }
Beispiel #20
0
 internal virtual DerSet CreateDerSet(DefiniteLengthInputStream dIn) =>
 DerSet.FromVector(this.BuildDerEncodableVector(dIn), false);
Beispiel #21
0
 internal virtual DerSet CreateDerSet(
     DefiniteLengthInputStream dIn)
 {
     return(DerSet.FromVector(ReadVector(dIn), false));
 }
        internal virtual DerSet CreateDerSet(
			DefiniteLengthInputStream dIn)
        {
            return DerSet.FromVector(BuildDerEncodableVector(dIn), false);
        }
Beispiel #23
0
 internal virtual DerSequence CreateDerSequence(
     DefiniteLengthInputStream dIn)
 {
     return(DerSequence.FromVector(ReadVector(dIn)));
 }
Beispiel #24
0
        public virtual IAsn1Convertible ReadObject()
        {
            int num = this._in.ReadByte();

            if (num == -1)
            {
                return(null);
            }
            this.Set00Check(false);
            int  num2 = Asn1InputStream.ReadTagNumber(this._in, num);
            bool flag = (num & 32) != 0;
            int  num3 = Asn1InputStream.ReadLength(this._in, this._limit);

            if (num3 < 0)
            {
                if (!flag)
                {
                    throw new IOException("indefinite length primitive encoding encountered");
                }
                IndefiniteLengthInputStream inStream         = new IndefiniteLengthInputStream(this._in, this._limit);
                Asn1StreamParser            asn1StreamParser = new Asn1StreamParser(inStream, this._limit);
                if ((num & 64) != 0)
                {
                    return(new BerApplicationSpecificParser(num2, asn1StreamParser));
                }
                if ((num & 128) != 0)
                {
                    return(new BerTaggedObjectParser(true, num2, asn1StreamParser));
                }
                return(asn1StreamParser.ReadIndef(num2));
            }
            else
            {
                DefiniteLengthInputStream definiteLengthInputStream = new DefiniteLengthInputStream(this._in, num3);
                if ((num & 64) != 0)
                {
                    return(new DerApplicationSpecific(flag, num2, definiteLengthInputStream.ToArray()));
                }
                if ((num & 128) != 0)
                {
                    return(new BerTaggedObjectParser(flag, num2, new Asn1StreamParser(definiteLengthInputStream)));
                }
                if (flag)
                {
                    int num4 = num2;
                    if (num4 == 4)
                    {
                        return(new BerOctetStringParser(new Asn1StreamParser(definiteLengthInputStream)));
                    }
                    if (num4 == 8)
                    {
                        return(new DerExternalParser(new Asn1StreamParser(definiteLengthInputStream)));
                    }
                    switch (num4)
                    {
                    case 16:
                        return(new DerSequenceParser(new Asn1StreamParser(definiteLengthInputStream)));

                    case 17:
                        return(new DerSetParser(new Asn1StreamParser(definiteLengthInputStream)));

                    default:
                        throw new IOException("unknown tag " + num2 + " encountered");
                    }
                }
                else
                {
                    int num5 = num2;
                    if (num5 == 4)
                    {
                        return(new DerOctetStringParser(definiteLengthInputStream));
                    }
                    IAsn1Convertible result;
                    try
                    {
                        result = Asn1InputStream.CreatePrimitiveDerObject(num2, definiteLengthInputStream, this.tmpBuffers);
                    }
                    catch (ArgumentException exception)
                    {
                        throw new Asn1Exception("corrupted stream detected", exception);
                    }
                    return(result);
                }
            }
        }
Beispiel #25
0
        internal static Asn1Object CreatePrimitiveDerObject(int tagNo, DefiniteLengthInputStream defIn, byte[][] tmpBuffers)
        {
            if (tagNo != 1)
            {
                if (tagNo == 10)
                {
                    return(DerEnumerated.FromOctetString(GetBuffer(defIn, tmpBuffers)));
                }
                if (tagNo == 6)
                {
                    return(DerObjectIdentifier.FromOctetString(GetBuffer(defIn, tmpBuffers)));
                }
            }
            else
            {
                return(DerBoolean.FromOctetString(GetBuffer(defIn, tmpBuffers)));
            }
            byte[] str = defIn.ToArray();
            switch (tagNo)
            {
            case 0x12:
                return(new DerNumericString(str));

            case 0x13:
                return(new DerPrintableString(str));

            case 20:
                return(new DerT61String(str));

            case 0x15:
                return(new DerVideotexString(str));

            case 0x16:
                return(new DerIA5String(str));

            case 0x17:
                return(new DerUtcTime(str));

            case 0x18:
                return(new DerGeneralizedTime(str));

            case 0x19:
                return(new DerGraphicString(str));

            case 0x1a:
                return(new DerVisibleString(str));

            case 0x1b:
                return(new DerGeneralString(str));

            case 0x1c:
                return(new DerUniversalString(str));

            case 30:
                return(new DerBmpString(str));

            case 2:
                return(new DerInteger(str));

            case 3:
                return(DerBitString.FromAsn1Octets(str));

            case 4:
                return(new DerOctetString(str));

            case 5:
                return(DerNull.Instance);

            case 12:
                return(new DerUtf8String(str));
            }
            throw new IOException("unknown tag " + tagNo + " encountered");
        }
        internal virtual Asn1EncodableVector BuildDerEncodableVector(
			DefiniteLengthInputStream dIn)
        {
            return new Asn1InputStream(dIn).BuildEncodableVector();
        }
        public Asn1Object ReadObject()
        {
            int tag = ReadByte();

            if (tag <= 0)
            {
                if (tag == 0)
                {
                    throw new IOException("unexpected end-of-contents marker");
                }

                return(null);
            }

            //
            // calculate tag number
            //
            int tagNo = ReadTagNumber(this, tag);

            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;

            //
            // calculate length
            //
            int length = ReadLength(this, limit);

            if (length < 0)             // indefinite length method
            {
                if (!isConstructed)
                {
                    throw new IOException("indefinite length primitive encoding encountered");
                }

                IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(this);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    Asn1StreamParser sp2 = new Asn1StreamParser(indIn, limit);

                    return(new BerApplicationSpecificParser(tagNo, sp2).ToAsn1Object());
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    // TODO Investigate passing an Asn1StreamParser into this constructor
                    return(new BerTaggedObjectParser(tag, tagNo, indIn).ToAsn1Object());
                }

                Asn1StreamParser sp = new Asn1StreamParser(indIn, limit);

                // TODO There are other tags that may be constructed (e.g. BitString)
                switch (tagNo)
                {
                case Asn1Tags.OctetString:
                    return(new BerOctetStringParser(sp).ToAsn1Object());

                case Asn1Tags.Sequence:
                    return(new BerSequenceParser(sp).ToAsn1Object());

                case Asn1Tags.Set:
                    return(new BerSetParser(sp).ToAsn1Object());

                case Asn1Tags.External:
                    return(new DerExternalParser(sp).ToAsn1Object());

                default:
                    throw new IOException("unknown BER object encountered");
                }
            }
            else
            {
                DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(this, length);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    return(new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray()));
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    return(new BerTaggedObjectParser(tag, tagNo, defIn).ToAsn1Object());
                }

                if (isConstructed)
                {
                    // TODO There are other tags that may be constructed (e.g. BitString)
                    switch (tagNo)
                    {
                    case Asn1Tags.OctetString:
                        //
                        // yes, people actually do this...
                        //
                        return(new BerOctetString(BuildDerEncodableVector(defIn)));

                    case Asn1Tags.Sequence:
                        return(CreateDerSequence(defIn));

                    case Asn1Tags.Set:
                        return(CreateDerSet(defIn));

                    case Asn1Tags.External:
                        return(new DerExternal(BuildDerEncodableVector(defIn)));

                    default:
                        return(new DerUnknownTag(true, tagNo, defIn.ToArray()));
                    }
                }

                return(CreatePrimitiveDerObject(tagNo, defIn.ToArray()));
            }
        }
        internal virtual DerSequence CreateDerSequence(
			DefiniteLengthInputStream dIn)
        {
            return DerSequence.FromVector(BuildDerEncodableVector(dIn));
        }
Beispiel #29
0
 internal virtual DerSequence CreateDerSequence(DefiniteLengthInputStream dIn) =>
 DerSequence.FromVector(this.BuildDerEncodableVector(dIn));
        public Asn1Object ReadObject()
        {
            int tag = ReadByte();
            if (tag <= 0)
            {
                if (tag == 0)
                    throw new IOException("unexpected end-of-contents marker");

                return null;
            }

            //
            // calculate tag number
            //
            int tagNo = ReadTagNumber(this, tag);

            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;

            //
            // calculate length
            //
            int length = ReadLength(this, limit);

            if (length < 0) // indefinite length method
            {
                if (!isConstructed)
                    throw new IOException("indefinite length primitive encoding encountered");

                IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(this);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    Asn1StreamParser sp2 = new Asn1StreamParser(indIn);

                    return new BerApplicationSpecificParser(tagNo, sp2).ToAsn1Object();
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    // TODO Investigate passing an Asn1StreamParser into this constructor
                    return new BerTaggedObjectParser(tag, tagNo, indIn).ToAsn1Object();
                }

                Asn1StreamParser sp = new Asn1StreamParser(indIn);

                // TODO There are other tags that may be constructed (e.g. BitString)
                switch (tagNo)
                {
                    case Asn1Tags.OctetString:
                        return new BerOctetStringParser(sp).ToAsn1Object();
                    case Asn1Tags.Sequence:
                        return new BerSequenceParser(sp).ToAsn1Object();
                    case Asn1Tags.Set:
                        return new BerSetParser(sp).ToAsn1Object();
                    default:
                        throw new IOException("unknown BER object encountered");
                }
            }
            else
            {
                DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(this, length);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    return new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray());
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    return new BerTaggedObjectParser(tag, tagNo, defIn).ToAsn1Object();
                }

                if (isConstructed)
                {
                    // TODO There are other tags that may be constructed (e.g. BitString)
                    switch (tagNo)
                    {
                        case Asn1Tags.OctetString:
                            //
                            // yes, people actually do this...
                            //
                            return new BerOctetString(BuildDerEncodableVector(defIn));
                        case Asn1Tags.Sequence:
                            return CreateDerSequence(defIn);
                        case Asn1Tags.Set:
                            return CreateDerSet(defIn);
                        default:
                            return new DerUnknownTag(true, tagNo, defIn.ToArray());
                    }
                }

                return CreatePrimitiveDerObject(tagNo, defIn.ToArray());
            }
        }
Beispiel #31
0
        internal static Asn1Object CreatePrimitiveDerObject(int tagNo, DefiniteLengthInputStream defIn, byte[][] tmpBuffers)
        {
            //IL_014a: Unknown result type (might be due to invalid IL or missing references)
            switch (tagNo)
            {
            case 1:
                return(DerBoolean.FromOctetString(GetBuffer(defIn, tmpBuffers)));

            case 10:
                return(DerEnumerated.FromOctetString(GetBuffer(defIn, tmpBuffers)));

            case 6:
                return(DerObjectIdentifier.FromOctetString(GetBuffer(defIn, tmpBuffers)));

            default:
            {
                byte[] array = defIn.ToArray();
                switch (tagNo)
                {
                case 3:
                    return(DerBitString.FromAsn1Octets(array));

                case 30:
                    return(new DerBmpString(array));

                case 24:
                    return(new DerGeneralizedTime(array));

                case 27:
                    return(new DerGeneralString(array));

                case 25:
                    return(new DerGraphicString(array));

                case 22:
                    return(new DerIA5String(array));

                case 2:
                    return(new DerInteger(array));

                case 5:
                    return(DerNull.Instance);

                case 18:
                    return(new DerNumericString(array));

                case 4:
                    return(new DerOctetString(array));

                case 19:
                    return(new DerPrintableString(array));

                case 20:
                    return(new DerT61String(array));

                case 28:
                    return(new DerUniversalString(array));

                case 23:
                    return(new DerUtcTime(array));

                case 12:
                    return(new DerUtf8String(array));

                case 21:
                    return(new DerVideotexString(array));

                case 26:
                    return(new DerVisibleString(array));

                default:
                    throw new IOException(string.Concat((object)"unknown tag ", (object)tagNo, (object)" encountered"));
                }
            }
            }
        }
Beispiel #32
0
 internal override DerSet CreateDerSet(
     DefiniteLengthInputStream dIn)
 {
     return(new LazyDerSet(dIn.ToArray()));
 }
        public virtual IAsn1Convertible ReadObject()
        {
            //IL_004f: Unknown result type (might be due to invalid IL or missing references)
            //IL_014a: Unknown result type (might be due to invalid IL or missing references)
            //IL_0174: Expected O, but got Unknown
            int num = _in.ReadByte();

            if (num == -1)
            {
                return(null);
            }
            Set00Check(enabled: false);
            int  num2 = Asn1InputStream.ReadTagNumber(_in, num);
            bool flag = (num & 0x20) != 0;
            int  num3 = Asn1InputStream.ReadLength(_in, _limit);

            if (num3 < 0)
            {
                if (!flag)
                {
                    throw new IOException("indefinite length primitive encoding encountered");
                }
                IndefiniteLengthInputStream inStream         = new IndefiniteLengthInputStream(_in, _limit);
                Asn1StreamParser            asn1StreamParser = new Asn1StreamParser((Stream)(object)inStream, _limit);
                if (((uint)num & 0x40u) != 0)
                {
                    return(new BerApplicationSpecificParser(num2, asn1StreamParser));
                }
                if (((uint)num & 0x80u) != 0)
                {
                    return(new BerTaggedObjectParser(constructed: true, num2, asn1StreamParser));
                }
                return(asn1StreamParser.ReadIndef(num2));
            }
            DefiniteLengthInputStream definiteLengthInputStream = new DefiniteLengthInputStream(_in, num3);

            if (((uint)num & 0x40u) != 0)
            {
                return(new DerApplicationSpecific(flag, num2, definiteLengthInputStream.ToArray()));
            }
            if (((uint)num & 0x80u) != 0)
            {
                return(new BerTaggedObjectParser(flag, num2, new Asn1StreamParser((Stream)(object)definiteLengthInputStream)));
            }
            if (flag)
            {
                switch (num2)
                {
                case 4:
                    return(new BerOctetStringParser(new Asn1StreamParser((Stream)(object)definiteLengthInputStream)));

                case 16:
                    return(new DerSequenceParser(new Asn1StreamParser((Stream)(object)definiteLengthInputStream)));

                case 17:
                    return(new DerSetParser(new Asn1StreamParser((Stream)(object)definiteLengthInputStream)));

                case 8:
                    return(new DerExternalParser(new Asn1StreamParser((Stream)(object)definiteLengthInputStream)));

                default:
                    throw new IOException(string.Concat((object)"unknown tag ", (object)num2, (object)" encountered"));
                }
            }
            int num4 = num2;

            if (num4 == 4)
            {
                return(new DerOctetStringParser(definiteLengthInputStream));
            }
            try
            {
                return(Asn1InputStream.CreatePrimitiveDerObject(num2, definiteLengthInputStream, tmpBuffers));
            }
            catch (ArgumentException val)
            {
                ArgumentException exception = val;
                throw new Asn1Exception("corrupted stream detected", (global::System.Exception)(object) exception);
            }
        }
Beispiel #34
0
        public virtual IAsn1Convertible ReadObject()
        {
            int tag = _in.ReadByte();

            if (tag == -1)
            {
                return(null);
            }

            // turn of looking for "00" while we resolve the tag
            Set00Check(false);

            //
            // calculate tag number
            //
            int tagNo = Asn1InputStream.ReadTagNumber(_in, tag);

            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;

            //
            // calculate length
            //
            int length = Asn1InputStream.ReadLength(_in, _limit);

            if (length < 0)             // indefinite length method
            {
                if (!isConstructed)
                {
                    throw new IOException("indefinite length primitive encoding encountered");
                }

                IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in, _limit);
                Asn1StreamParser            sp    = new Asn1StreamParser(indIn, _limit);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    return(new BerApplicationSpecificParser(tagNo, sp));
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    return(new BerTaggedObjectParser(true, tagNo, sp));
                }

                return(sp.ReadIndef(tagNo));
            }
            else
            {
                DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    return(new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray()));
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    return(new BerTaggedObjectParser(isConstructed, tagNo, new Asn1StreamParser(defIn)));
                }

                if (isConstructed)
                {
                    // TODO There are other tags that may be constructed (e.g. BitString)
                    switch (tagNo)
                    {
                    case Asn1Tags.OctetString:
                        //
                        // yes, people actually do this...
                        //
                        return(new BerOctetStringParser(new Asn1StreamParser(defIn)));

                    case Asn1Tags.Sequence:
                        return(new DerSequenceParser(new Asn1StreamParser(defIn)));

                    case Asn1Tags.Set:
                        return(new DerSetParser(new Asn1StreamParser(defIn)));

                    case Asn1Tags.External:
                        return(new DerExternalParser(new Asn1StreamParser(defIn)));

                    default:
                        throw new IOException("unknown tag " + tagNo + " encountered");
                    }
                }

                // Some primitive encodings can be handled by parsers too...
                switch (tagNo)
                {
                case Asn1Tags.OctetString:
                    return(new DerOctetStringParser(defIn));
                }

                try
                {
                    return(Asn1InputStream.CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers));
                }
                catch (ArgumentException e)
                {
                    throw new Asn1Exception("corrupted stream detected", e);
                }
            }
        }
Beispiel #35
0
        public IAsn1Convertible ReadObject()
        {
            int tag = _in.ReadByte();

            if (tag == -1)
            {
                if (_eofFound)
                {
                    throw new EndOfStreamException("attempt to read past end of file.");
                }

                _eofFound = true;

                return(null);
            }

            //
            // turn of looking for "00" while we resolve the tag
            //
            if (_in is IndefiniteLengthInputStream)
            {
                ((IndefiniteLengthInputStream)_in).SetEofOn00(false);
            }

            //
            // calculate tag number
            //
            int baseTagNo = tag & ~Asn1Tags.Constructed;
            int tagNo     = baseTagNo;

            if ((tag & Asn1Tags.Tagged) != 0)
            {
                tagNo = tag & 0x1f;

                //
                // with tagged object tag number is bottom 5 bits, or stored at the start of the content
                //
                if (tagNo == 0x1f)
                {
                    tagNo = 0;

                    int b = _in.ReadByte();

                    while ((b >= 0) && ((b & 0x80) != 0))
                    {
                        tagNo  |= (b & 0x7f);
                        tagNo <<= 7;
                        b       = _in.ReadByte();
                    }

                    if (b < 0)
                    {
                        _eofFound = true;

                        throw new EndOfStreamException("EOF encountered inside tag value.");
                    }

                    tagNo |= (b & 0x7f);
                }
            }

            //
            // calculate length
            //
            int length = ReadLength();

            if (length < 0)              // indefinite length
            {
                IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in);

                if (baseTagNo == Asn1Tags.Null)
                {
                    return(BerNull.Instance);
                }

                switch (baseTagNo)
                {
                case Asn1Tags.OctetString:
                    return(new BerOctetStringParser(new Asn1ObjectParser(tag, tagNo, indIn)));

                case Asn1Tags.Sequence:
                    return(new BerSequenceParser(new Asn1ObjectParser(tag, tagNo, indIn)));

                case Asn1Tags.Set:
                    return(new BerSetParser(new Asn1ObjectParser(tag, tagNo, indIn)));

                default:
                    return(new BerTaggedObjectParser(tag, tagNo, indIn));
                }
            }
            else
            {
                DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length);

                switch (baseTagNo)
                {
                case Asn1Tags.Integer:
                    return(new DerInteger(defIn.ToArray()));

                case Asn1Tags.Null:
                    return(DerNull.Instance);

                case Asn1Tags.ObjectIdentifier:
                    return(new DerObjectIdentifier(defIn.ToArray()));

                case Asn1Tags.OctetString:
                    return(new DerOctetString(defIn.ToArray()));

                case Asn1Tags.Sequence:
                    return(new DerSequence(loadVector(defIn.ToArray())).Parser);

                case Asn1Tags.Set:
                    return(new DerSet(loadVector(defIn.ToArray())).Parser);

                default:
                    return(new BerTaggedObjectParser(tag, tagNo, defIn));
                }
            }
        }
Beispiel #36
0
 internal virtual Asn1EncodableVector BuildDerEncodableVector(
     DefiniteLengthInputStream dIn)
 {
     return(new Asn1InputStream(dIn).BuildEncodableVector());
 }
        public virtual IAsn1Convertible ReadObject()
        {
            int tag = _in.ReadByte();
            if (tag == -1)
                return null;

            // turn of looking for "00" while we resolve the tag
            Set00Check(false);

            //
            // calculate tag number
            //
            int tagNo = Asn1InputStream.ReadTagNumber(_in, tag);

            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;

            //
            // calculate length
            //
            int length = Asn1InputStream.ReadLength(_in, _limit);

            if (length < 0) // indefinite length method
            {
                if (!isConstructed)
                    throw new IOException("indefinite length primitive encoding encountered");

                IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in, _limit);
                Asn1StreamParser sp = new Asn1StreamParser(indIn, _limit);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    return new BerApplicationSpecificParser(tagNo, sp);
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    return new BerTaggedObjectParser(true, tagNo, sp);
                }

                return sp.ReadIndef(tagNo);
            }
            else
            {
                DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length);

                if ((tag & Asn1Tags.Application) != 0)
                {
                    return new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray());
                }

                if ((tag & Asn1Tags.Tagged) != 0)
                {
                    return new BerTaggedObjectParser(isConstructed, tagNo, new Asn1StreamParser(defIn));
                }

                if (isConstructed)
                {
                    // TODO There are other tags that may be constructed (e.g. BitString)
                    switch (tagNo)
                    {
                        case Asn1Tags.OctetString:
                            //
                            // yes, people actually do this...
                            //
                            return new BerOctetStringParser(new Asn1StreamParser(defIn));
                        case Asn1Tags.Sequence:
                            return new DerSequenceParser(new Asn1StreamParser(defIn));
                        case Asn1Tags.Set:
                            return new DerSetParser(new Asn1StreamParser(defIn));
                        case Asn1Tags.External:
                            return new DerExternalParser(new Asn1StreamParser(defIn));
                        default:
                            // TODO Add DerUnknownTagParser class?
                            return new DerUnknownTag(true, tagNo, defIn.ToArray());
                    }
                }

                // Some primitive encodings can be handled by parsers too...
                switch (tagNo)
                {
                    case Asn1Tags.OctetString:
                        return new DerOctetStringParser(defIn);
                }

                try
                {
                    return Asn1InputStream.CreatePrimitiveDerObject(tagNo, defIn.ToArray());
                }
                catch (ArgumentException e)
                {
                    throw new Asn1Exception("corrupted stream detected", e);
                }
            }
        }
Beispiel #38
0
 internal virtual DerSet CreateDerSet(
     DefiniteLengthInputStream dIn)
 {
     return(DerSet.FromVector(BuildDerEncodableVector(dIn), false));
 }
        internal static byte[] GetBuffer(DefiniteLengthInputStream defIn, byte[][] tmpBuffers)
        {
            int len = defIn.GetRemaining();
            if (len >= tmpBuffers.Length)
            {
                return defIn.ToArray();
            }

            byte[] buf = tmpBuffers[len];
            if (buf == null)
            {
                buf = tmpBuffers[len] = new byte[len];
            }

            defIn.ReadAllIntoByteArray(buf);

            return buf;
        }
Beispiel #40
0
        /**
         * build an object given its tag and the number of bytes to construct it from.
         */
        private Asn1Object BuildObject(
            int tag,
            int tagNo,
            int length)
        {
            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;

            DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(this.s, length, limit);

            if ((tag & Asn1Tags.Application) != 0)
            {
                return(new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray()));
            }

            if ((tag & Asn1Tags.Tagged) != 0)
            {
                return(new Asn1StreamParser(defIn).ReadTaggedObject(isConstructed, tagNo));
            }

            if (isConstructed)
            {
                // TODO There are other tags that may be constructed (e.g. BitString)
                switch (tagNo)
                {
                case Asn1Tags.OctetString:
                {
                    //
                    // yes, people actually do this...
                    //
                    Asn1EncodableVector v       = ReadVector(defIn);
                    Asn1OctetString[]   strings = new Asn1OctetString[v.Count];

                    for (int i = 0; i != strings.Length; i++)
                    {
                        Asn1Encodable asn1Obj = v[i];
                        if (!(asn1Obj is Asn1OctetString))
                        {
                            throw new Asn1Exception("unknown object encountered in constructed OCTET STRING: "
                                                    + Platform.GetTypeName(asn1Obj));
                        }

                        strings[i] = (Asn1OctetString)asn1Obj;
                    }

                    return(new BerOctetString(strings));
                }

                case Asn1Tags.Sequence:
                    return(CreateDerSequence(defIn));

                case Asn1Tags.Set:
                    return(CreateDerSet(defIn));

                case Asn1Tags.External:
                    return(new DerExternal(ReadVector(defIn)));

                default:
                    throw new IOException("unknown tag " + tagNo + " encountered");
                }
            }

            return(CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers));
        }
Beispiel #41
0
        public IAsn1Convertible ReadObject()
        {
            int tag = _in.ReadByte();
            if (tag == -1)
            {
                if (_eofFound)
                    throw new EndOfStreamException("attempt to read past end of file.");

                _eofFound = true;

                return null;
            }

            //
            // turn of looking for "00" while we resolve the tag
            //
            if (_in is IndefiniteLengthInputStream)
            {
                ((IndefiniteLengthInputStream)_in).SetEofOn00(false);
            }

            //
            // calculate tag number
            //
            int baseTagNo = tag & ~Asn1Tags.Constructed;
            int tagNo = baseTagNo;

            if ((tag & Asn1Tags.Tagged) != 0)
            {
                tagNo = tag & 0x1f;

                //
                // with tagged object tag number is bottom 5 bits, or stored at the start of the content
                //
                if (tagNo == 0x1f)
                {
                    tagNo = 0;

                    int b = _in.ReadByte();

                    while ((b >= 0) && ((b & 0x80) != 0))
                    {
                        tagNo |= (b & 0x7f);
                        tagNo <<= 7;
                        b = _in.ReadByte();
                    }

                    if (b < 0)
                    {
                        _eofFound = true;

                        throw new EndOfStreamException("EOF encountered inside tag value.");
                    }

                    tagNo |= (b & 0x7f);
                }
            }

            //
            // calculate length
            //
            int length = ReadLength();

            if (length < 0)  // indefinite length
            {
                IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in);

                if (baseTagNo == Asn1Tags.Null)
                {
                    return BerNull.Instance;
                }

                switch (baseTagNo)
                {
                    case Asn1Tags.OctetString:
                        return new BerOctetStringParser(new Asn1ObjectParser(tag, tagNo, indIn));
                    case Asn1Tags.Sequence:
                        return new BerSequenceParser(new Asn1ObjectParser(tag, tagNo, indIn));
                    case Asn1Tags.Set:
                        return new BerSetParser(new Asn1ObjectParser(tag, tagNo, indIn));
                    default:
                        return new BerTaggedObjectParser(tag, tagNo, indIn);
                }
            }
            else
            {
                DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length);

                switch (baseTagNo)
                {
                    case Asn1Tags.Integer:
                        return new DerInteger(defIn.ToArray());
                    case Asn1Tags.Null:
                        return DerNull.Instance;
                    case Asn1Tags.ObjectIdentifier:
                        return new DerObjectIdentifier(defIn.ToArray());
                    case Asn1Tags.OctetString:
                        return new DerOctetString(defIn.ToArray());
                    case Asn1Tags.Sequence:
                        return new DerSequence(loadVector(defIn.ToArray())).Parser;
                    case Asn1Tags.Set:
                        return new DerSet(loadVector(defIn.ToArray())).Parser;
                    default:
                        return new BerTaggedObjectParser(tag, tagNo, defIn);
                }
            }
        }