Esempio n. 1
0
 public virtual long DecodeIntValue(int length, bool signExtend)
 {
     return(Asn1RunTime.DecodeIntValue(this, length, signExtend));
 }
Esempio n. 2
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;
            }
        }