CreatePrimitiveDerObject() 정적인 개인적인 메소드

static private CreatePrimitiveDerObject ( int tagNo, DefiniteLengthInputStream defIn, byte tmpBuffers ) : Asn1Object
tagNo int
defIn DefiniteLengthInputStream
tmpBuffers byte
리턴 Asn1Object
예제 #1
0
        private Asn1Object BuildObject(int tag, int tagNo, int length)
        {
            bool flag = (tag & 32) != 0;
            DefiniteLengthInputStream definiteLengthInputStream = new DefiniteLengthInputStream(this.s, length);

            if ((tag & 64) != 0)
            {
                return(new DerApplicationSpecific(flag, tagNo, definiteLengthInputStream.ToArray()));
            }
            if ((tag & 128) != 0)
            {
                return(new Asn1StreamParser(definiteLengthInputStream).ReadTaggedObject(flag, tagNo));
            }
            if (!flag)
            {
                return(Asn1InputStream.CreatePrimitiveDerObject(tagNo, definiteLengthInputStream, this.tmpBuffers));
            }
            if (tagNo == 4)
            {
                return(new BerOctetString(this.BuildDerEncodableVector(definiteLengthInputStream)));
            }
            if (tagNo == 8)
            {
                return(new DerExternal(this.BuildDerEncodableVector(definiteLengthInputStream)));
            }
            switch (tagNo)
            {
            case 16:
                return(this.CreateDerSequence(definiteLengthInputStream));

            case 17:
                return(this.CreateDerSet(definiteLengthInputStream));

            default:
                throw new IOException("unknown tag " + tagNo + " encountered");
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
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);
        }
예제 #5
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);
                }
            }
        }
예제 #6
0
        public virtual IAsn1Convertible ReadObject()
        {
            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(inStream, _limit);
                if ((num & 0x40) != 0)
                {
                    return(new BerApplicationSpecificParser(num2, asn1StreamParser));
                }
                if ((num & 0x80) != 0)
                {
                    return(new BerTaggedObjectParser(constructed: true, num2, asn1StreamParser));
                }
                return(asn1StreamParser.ReadIndef(num2));
            }
            DefiniteLengthInputStream definiteLengthInputStream = new DefiniteLengthInputStream(_in, num3);

            if ((num & 0x40) != 0)
            {
                return(new DerApplicationSpecific(flag, num2, definiteLengthInputStream.ToArray()));
            }
            if ((num & 0x80) != 0)
            {
                return(new BerTaggedObjectParser(flag, num2, new Asn1StreamParser(definiteLengthInputStream)));
            }
            if (flag)
            {
                switch (num2)
                {
                case 4:
                    return(new BerOctetStringParser(new Asn1StreamParser(definiteLengthInputStream)));

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

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

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

                default:
                    throw new IOException("unknown tag " + num2 + " encountered");
                }
            }
            int num4 = num2;

            if (num4 != 4)
            {
                try
                {
                    return(Asn1InputStream.CreatePrimitiveDerObject(num2, definiteLengthInputStream, tmpBuffers));

IL_019e:
                    IAsn1Convertible result;
                    return(result);
                }
                catch (ArgumentException exception)
                {
                    throw new Asn1Exception("corrupted stream detected", exception);
IL_01b2:
                    IAsn1Convertible result;
                    return(result);
                }
            }
            return(new DerOctetStringParser(definiteLengthInputStream));
        }