Exemplo n.º 1
0
        public virtual void EncodeIdentifier(long ident)
        {
            var number          = 0x7fL;
            var identBytesCount = Asn1RunTime.GetIdentBytesCount(ident);

            number = number << (7 * identBytesCount);

            if (identBytesCount > 0)
            {
                while (identBytesCount > 0)
                {
                    number = Asn1Util.UrShift(number, 7);
                    identBytesCount--;

                    var num3 = Asn1Util.UrShift(ident & number, identBytesCount * 7);

                    if (identBytesCount != 0)
                    {
                        num3 |= 0x80L;
                    }

                    OutputStream.WriteByte((byte)num3);
                }
            }
            else
            {
                OutputStream.WriteByte(0);
            }
        }
Exemplo n.º 2
0
        public override void Encode(Asn1BerOutputStream outs, bool explicitTagging)
        {
            int num;

            if (((Value.Length < 2) || (Value[0] > 2)) || ((Value[0] != 2) && (Value[1] > 0x27)))
            {
                throw new Exception("Asn1InvalidObjectIdException");
            }

            var len = 1;

            for (num = 2; num < Value.Length; num++)
            {
                len += Asn1RunTime.GetIdentBytesCount(Value[num]);
            }

            if (explicitTagging)
            {
                outs.EncodeTag(Tag);
            }

            outs.EncodeLength(len);
            var ident = (Value[0] * 40) + Value[1];

            outs.EncodeIdentifier(ident);

            for (num = 2; num < Value.Length; num++)
            {
                outs.EncodeIdentifier(Value[num]);
            }
        }
Exemplo n.º 3
0
        private static int TrailingZerosCnt(long w)
        {
            var num = Asn1RunTime.IntTrailingZerosCnt((int)w);

            if (num >= RealBase16)
            {
                return(Asn1RunTime.IntTrailingZerosCnt((int)Asn1Util.UrShift(w, RealBase16)) + RealBase16);
            }

            return(num);
        }
Exemplo n.º 4
0
 public static int GetUlongBytesCount(long val)
 {
     return(Asn1RunTime.GetUlongBytesCount(val));
 }
Exemplo n.º 5
0
 public virtual long DecodeIntValue(int length, bool signExtend)
 {
     return(Asn1RunTime.DecodeIntValue(this, length, signExtend));
 }
Exemplo n.º 6
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;
            }
        }