Esempio n. 1
0
        public virtual void DecodeComponent(Asn1BerDecodeBuffer buffer)
        {
            var type = new Asn1OpenType();

            type.Decode(buffer, false, 0);
            Value.Add(type);
        }
Esempio n. 2
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var llen    = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var idx     = new IntHolder(0);
            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                ReadSegment(buffer, llen, idx);
            }
            else
            {
                var context = new Asn1BerDecodeContext(buffer, llen);

                while (!context.Expired())
                {
                    var num2 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num2 <= 0)
                    {
                        throw new FormatException("Asn1InvalidFormatOfConstructedValue");
                    }

                    ReadSegment(buffer, num2, idx);
                }

                if (llen == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = UniversalStringTypeCode;
        }
Esempio n. 3
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var lastTag    = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (elemLength < 0)
                {
                    throw new Exception("Asn1InvalidLengthException");
                }

                Value = new byte[elemLength];

                if (elemLength != 0)
                {
                    buffer.Read(Value);
                }
            }
            else
            {
                var nbytes  = 0;
                var offset  = 0;
                var context = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num2 = MatchTag(buffer, Tag);

                    if (num2 <= 0)
                    {
                        throw new Exception("Asn1InvalidFormatOfConstructedValue");
                    }

                    nbytes += num2;

                    if (offset == 0)
                    {
                        Value = new byte[nbytes];
                    }
                    else
                    {
                        ReAllocByteArray(nbytes);
                    }

                    buffer.Read(Value, offset, num2);
                    offset = nbytes;
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = OctetStringTypeCode;
        }
Esempio n. 4
0
        protected virtual int MatchTag(Asn1BerDecodeBuffer buffer, short tagClass, short tagForm, int tagIdCode)
        {
            if (!buffer.MatchTag(tagClass, tagForm, tagIdCode, _parsedTag, _parsedLen))
            {
                throw new FormatException("Asn1TagMatchFailedException, new Asn1Tag(tagClass, tagForm, tagIdCode)");
            }

            return(_parsedLen.Value);
        }
Esempio n. 5
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var llen = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            if (llen <= 0)
            {
                throw new Exception("Asn1InvalidLengthException");
            }

            Value           = buffer.DecodeOidContents(llen);
            buffer.TypeCode = ObjectIdentifierTypeCode;
        }
Esempio n. 6
0
        public virtual void DecodeEventComponent(Asn1BerDecodeBuffer buffer)
        {
            buffer.InvokeStartElement("...", -1);

            var type = new Asn1OpenType();

            type.Decode(buffer, false, 0);

            Value.Add(type);

            buffer.InvokeCharacters(type.ToString());
            buffer.InvokeEndElement("...", -1);
        }
Esempio n. 7
0
        public static int CalcIndefLen(byte[] data, int offset, int len)
        {
            Asn1BerDecodeBuffer buffer;

            if ((offset == 0) && (len == data.Length))
            {
                buffer = new Asn1BerDecodeBuffer(data);
            }
            else
            {
                var destinationArray = new byte[len];
                Array.Copy(data, offset, destinationArray, 0, len);
                buffer = new Asn1BerDecodeBuffer(destinationArray);
            }

            var tag = new Asn1Tag();
            var num = buffer.DecodeTagAndLength(tag);

            if (num == Asn1Status.IndefiniteLength)
            {
                var num2 = 1;
                num = 0;

                while (num2 > 0)
                {
                    var byteCount = buffer.ByteCount;
                    var num4      = buffer.DecodeTagAndLength(tag);
                    num += buffer.ByteCount - byteCount;

                    if (num4 > 0)
                    {
                        buffer.Skip(num4);
                        num += num4;
                    }
                    else
                    {
                        if (num4 == Asn1Status.IndefiniteLength)
                        {
                            num2++;
                            continue;
                        }
                        if (tag.IsEoc() && (num4 == 0))
                        {
                            num2--;
                        }
                    }
                }
            }

            return(num);
        }
Esempio n. 8
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var num = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var str = new Asn1OctetString();

            str.Decode(buffer, false, num);

            Value = Encoding.UTF8.GetString(str.Value, 0, str.Value.Length);

            if (explicitTagging && (num == Asn1Status.IndefiniteLength))
            {
                MatchTag(buffer, Asn1Tag.Eoc);
            }
        }
Esempio n. 9
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var len        = elemLength;
            var sb         = new StringBuilder();

            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                sb.EnsureCapacity(elemLength / 2);
                ReadSegment(buffer, sb, len);
            }
            else
            {
                var capacity = 0;
                var context  = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num3 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num3 <= 0)
                    {
                        throw new Exception("Asn1 Invalid Format Of Constructed Value");
                    }

                    capacity += num3;
                    sb.EnsureCapacity(capacity);
                    ReadSegment(buffer, sb, num3);
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            Value           = sb.ToString();
            buffer.TypeCode = BmpStringTypeCode;
        }
Esempio n. 10
0
        private void ReadSegment(Asn1BerDecodeBuffer buffer, int llen, IntHolder idx)
        {
            if ((llen < 0) || ((llen % 4) != 0))
            {
                throw new FormatException("Asn1InvalidLengthException");
            }

            var num4 = llen / 4;

            if (_value.Length == 0)
            {
                _value = new int[num4];
            }
            else if ((idx.Value + num4) >= _value.Length)
            {
                ReallocIntArray(idx.Value + num4);
            }

            var value = idx.Value;

            while (value < (idx.Value + num4))
            {
                _value[value] = 0;

                for (var i = 0; i < 4; i++)
                {
                    var num = buffer.Read();

                    if (num == -1)
                    {
                        throw new FormatException("Asn1EndOfBufferException");
                    }

                    _value[value] = (_value[value] * 0x100) + num;
                }

                value++;
            }

            idx.Value = value;
        }
Esempio n. 11
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     Decode(buffer, explicitTagging, implicitLength, Tag);
 }
Esempio n. 12
0
 public virtual void Decode(Asn1BerDecodeBuffer buffer)
 {
     Decode(buffer, true, 0);
 }
Esempio n. 13
0
 public virtual void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
 }
Esempio n. 14
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     Value           = buffer.DecodeOpenType();
     buffer.TypeCode = OpenTypeTypeCode;
 }
Esempio n. 15
0
 protected virtual int MatchTag(Asn1BerDecodeBuffer buffer, Asn1Tag tag)
 {
     return(MatchTag(buffer, tag.Class, tag.Form, tag.IdCode));
 }
Esempio n. 16
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     DecodeComponent(buffer);
 }
Esempio n. 17
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var lastTag    = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (elemLength < 0)
                {
                    throw new Exception("Asn1 invalid length exception");
                }

                if (elemLength != 0)
                {
                    var num8 = elemLength - 1;
                    var num7 = buffer.Read();

                    if (num7 < 0)
                    {
                        throw new Exception("Asn1 end of buffer exception");
                    }

                    if ((num7 < 0) || (num7 > 7))
                    {
                        throw new Exception("Asn1 invalid format of bit string");
                    }

                    if ((num8 == 0) && (num7 != 0))
                    {
                        throw new Exception("Asn1 invalid length exception");
                    }

                    NumBits = (num8 * 8) - num7;
                    Value   = new byte[num8];
                    buffer.Read(Value);
                }
                else
                {
                    NumBits = 0;
                    Value   = null;
                }
            }
            else
            {
                var num3   = 0;
                var offset = 0;
                var index  = -1;
                var num6   = 0;

                var context = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var nbytes = MatchTag(buffer, Tag);

                    if (nbytes <= 0)
                    {
                        throw new Exception("Asn1 invalid format of constructed value");
                    }

                    num3 += nbytes;

                    if (offset == 0)
                    {
                        AllocBitArray(num3 * 8);
                    }
                    else
                    {
                        ReallocBitArray(num3 * 8);
                    }

                    index = offset;
                    buffer.Read(Value, offset, nbytes);
                    offset = num3;
                }

                if (index >= 0)
                {
                    num6 = Value[index];

                    if (((offset - index) - 1) > 0)
                    {
                        Array.Copy(Value, index + 1, Value, index, (offset - index) - 1);
                    }

                    num3--;
                }

                if ((num6 < 0) || (num6 > 7))
                {
                    throw new Exception("Asn1 invalid format of bit string");
                }

                ReallocBitArray((num3 * 8) - num6);

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = 3;
        }
Esempio n. 18
0
        public override void BinDump(StreamWriter outs, string varName)
        {
            var buffer = new Asn1BerDecodeBuffer(ByteArrayInputStream);

            buffer.Parse(new Asn1BerMessageDumpHandler(outs));
        }
Esempio n. 19
0
        protected virtual void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength, Asn1Tag tag)
        {
            int num2;
            var elemLength = explicitTagging ? MatchTag(buffer, tag) : implicitLength;
            var num3       = elemLength;
            var num4       = 0;

            if (StringBuffer == null)
            {
                StringBuffer = new StringBuilder();
            }

            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (num3 < 0)
                {
                    throw new Exception("Asn1InvalidLengthException");
                }

                StringBuffer.Length = num3;

                while (num3 > 0)
                {
                    num2 = buffer.Read();

                    if (num2 == -1)
                    {
                        throw new Exception("Asn1EndOfBufferException");
                    }

                    StringBuffer[num4++] = (char)num2;
                    num3--;
                }
            }
            else
            {
                var capacity = 0;
                var context  = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num5 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num5 <= 0)
                    {
                        throw new Exception("Asn1InvalidFormatOfConstructedValue");
                    }

                    capacity += num5;
                    StringBuffer.EnsureCapacity(capacity);

                    while (num5 > 0)
                    {
                        num2 = buffer.Read();

                        if (num2 == -1)
                        {
                            throw new Exception("Asn1EndOfBufferException");
                        }

                        StringBuffer.Append((char)num2);
                        num5--;
                    }
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            Value           = StringBuffer.ToString();
            buffer.TypeCode = (short)tag.IdCode;
        }
Esempio n. 20
0
 protected override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength, Asn1Tag tag)
 {
     Parsed = false;
     base.Decode(buffer, explicitTagging, implicitLength, tag);
     DerRules = buffer is Asn1DerDecodeBuffer;
 }
Esempio n. 21
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            if (length == 0)
            {
                Value = 0.0;
            }
            else
            {
                var num2 = buffer.ReadByte();

                if (length == 1)
                {
                    switch (num2)
                    {
                    case PlusInfinity:
                        Value = double.PositiveInfinity;
                        return;

                    case MinusInfinity:
                        Value = double.NegativeInfinity;
                        return;
                    }

                    throw new Exception("Asn1InvalidFormatOfConstructedValue");
                }

                length--;

                if ((num2 & RealBinary) == 0)
                {
                    var num8 = length;
                    var num9 = 0;

                    var builder = new StringBuilder {
                        Length = num8
                    };

                    while (num8 > 0)
                    {
                        var num7 = buffer.Read();

                        if (num7 == -1)
                        {
                            throw new Exception("Asn1EndOfBufferException");
                        }

                        builder[num9++] = (char)num7;
                        num8--;
                    }

                    var num10 = num2 & RealIso6093Mask;
                    var num11 = 0;

                    for (var i = 0; i < builder.Length; i++)
                    {
                        var ch = builder[i];

                        if ((num10 >= 2) && (ch == ','))
                        {
                            builder[i] = '.';
                            num11++;
                        }
                        else if (((num10 >= 1) && (((ch >= '0') && (ch <= '9')) || ((ch == '+') || (ch == '-')))) || (((num10 >= 2) && (ch == '.')) || ((num10 == 3) && ((ch == 'E') || (ch == 'e')))))
                        {
                            num11++;
                        }
                        else if ((num11 != 0) || (ch != ' '))
                        {
                            throw new Exception("Asn1InvalidFormatOfConstructedValue");
                        }
                    }
                    try
                    {
                        Value = double.Parse(builder.ToString());
                    }
                    catch (FormatException)
                    {
                        throw new Exception("Asn1InvalidFormatOfConstructedValue");
                    }
                }
                else
                {
                    int num6;
                    int num3;

                    switch ((num2 & RealExplenMask))
                    {
                    case RealExplen1:
                        num3 = 1;
                        break;

                    case RealExplen2:
                        num3 = 2;
                        break;

                    case RealExplen3:
                        num3 = 3;
                        break;

                    default:
                        num3 = buffer.ReadByte();
                        length--;
                        break;
                    }

                    var num4 = (int)Asn1RunTime.DecodeIntValue(buffer, num3, true);
                    length -= num3;

                    var num5 = Asn1RunTime.DecodeIntValue(buffer, length, false) * (1L << ((num2 & RealFactorMask) >> 2));

                    switch ((num2 & RealBaseMask))
                    {
                    case RealBase2:
                        num6 = 2;
                        break;

                    case RealBase8:
                        num6 = 8;
                        break;

                    case RealBase16:
                        num6 = 16;
                        break;

                    default:
                        throw new Exception("Asn1InvalidFormatOfConstructedValue");
                    }

                    Value = num5 * Math.Pow(num6, num4);

                    if ((num2 & PlusInfinity) != 0)
                    {
                        Value = -Value;
                    }
                }

                buffer.TypeCode = RealTypeCode;
            }
        }