コード例 #1
0
        protected bool GeneralDecode(Stream xdata)
        {
            bool flag = false;
            long num  = xdata.Length - xdata.Position;

            this.tag = (byte)xdata.ReadByte();
            long position = xdata.Position;

            this.dataLength = Asn1Util.DerLengthDecode(xdata, ref this.isIndefiniteLength);
            if (this.dataLength < 0L)
            {
                return(flag);
            }
            this.lengthFieldBytes = xdata.Position - position;
            if (num < this.dataLength + 1L + this.lengthFieldBytes || (this.ParentNode == null || ((int)this.ParentNode.tag & 32) == 0) && (((int)this.tag & 31) <= 0 || ((int)this.tag & 31) > 30))
            {
                return(flag);
            }
            if (this.tag == (byte)3)
            {
                if (this.dataLength < 1L)
                {
                    return(flag);
                }
                this.unusedBits = (byte)xdata.ReadByte();
                this.data       = new byte[this.dataLength - 1L];
                xdata.Read(this.data, 0, (int)(this.dataLength - 1L));
            }
            else
            {
                this.data = new byte[this.dataLength];
                xdata.Read(this.data, 0, (int)this.dataLength);
            }
            return(true);
        }
コード例 #2
0
        protected bool ListDecode(Stream xdata)
        {
            bool flag      = false;
            long position1 = xdata.Position;

            try
            {
                long num = xdata.Length - xdata.Position;
                this.tag = (byte)xdata.ReadByte();
                long position2 = xdata.Position;
                this.dataLength = Asn1Util.DerLengthDecode(xdata, ref this.isIndefiniteLength);
                if (this.dataLength < 0L || num < this.dataLength)
                {
                    return(flag);
                }
                this.lengthFieldBytes = xdata.Position - position2;
                long dataOffset = this.dataOffset + 1L + this.lengthFieldBytes;
                if (this.tag == (byte)3)
                {
                    this.unusedBits = (byte)xdata.ReadByte();
                    --this.dataLength;
                    ++dataOffset;
                }
                if (this.dataLength <= 0L)
                {
                    return(flag);
                }
                Stream xdata1 = (Stream) new MemoryStream((int)this.dataLength);
                byte[] buffer = new byte[this.dataLength];
                xdata.Read(buffer, 0, (int)this.dataLength);
                if (this.tag == (byte)3)
                {
                    ++this.dataLength;
                }
                xdata1.Write(buffer, 0, buffer.Length);
                xdata1.Position = 0L;
                while (xdata1.Position < xdata1.Length)
                {
                    Asn1Node xdata2 = new Asn1Node(this, dataOffset);
                    xdata2.parseEncapsulatedData = this.parseEncapsulatedData;
                    long position3 = xdata1.Position;
                    if (!xdata2.InternalLoadData(xdata1))
                    {
                        return(flag);
                    }
                    this.AddChild(xdata2);
                    long position4 = xdata1.Position;
                    dataOffset += position4 - position3;
                }
                flag = true;
                return(flag);
            }
            finally
            {
                if (!flag)
                {
                    xdata.Position = position1;
                    this.ClearAll();
                }
            }
        }