コード例 #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);
            }
        }
コード例 #2
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            Value           = (int)Asn1RunTime.DecodeIntValue(buffer, length, true);
            buffer.TypeCode = EnumeratedTypeCode;
        }
コード例 #3
0
        public override void Encode(Asn1BerOutputStream outs, bool explicitTagging)
        {
            if (((OidValue.Items.Length < 2) || (OidValue.Items[0] > 2)) || ((OidValue.Items[0] != 2) && (OidValue.Items[1] > 0x27)))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidObjectIdException);
            }

            var len = 1;

            for (var i = 2; i < OidValue.Items.Length; i++)
            {
                len += Asn1RunTime.GetIdentBytesCount(OidValue.Items[i]);
            }

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

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

            outs.EncodeIdentifier(ident);

            for (var i = 2; i < OidValue.Items.Length; i++)
            {
                outs.EncodeIdentifier(OidValue.Items[i]);
            }
        }
コード例 #4
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 ExceptionUtility.CryptographicException(Resources.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]);
            }
        }
コード例 #5
0
ファイル: Asn1Real.cs プロジェクト: xdios/GostCryptography
        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);
        }
コード例 #6
0
        public override void Encode(Asn1BerOutputStream outs, bool explicitTagging)
        {
            var len = 0;

            foreach (var i in OidValue.Items)
            {
                len += Asn1RunTime.GetIdentBytesCount(i);
            }

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

            outs.EncodeLength(len);

            foreach (var i in OidValue.Items)
            {
                outs.EncodeIdentifier(i);
            }
        }
コード例 #7
0
        public override void Encode(Asn1BerOutputStream outs, bool explicitTagging)
        {
            int num;
            var len = 0;

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

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

            outs.EncodeLength(len);

            for (num = 0; num < Value.Length; num++)
            {
                outs.EncodeIdentifier(Value[num]);
            }
        }
コード例 #8
0
 public static int GetUlongBytesCount(long val)
 {
     return(Asn1RunTime.GetUlongBytesCount(val));
 }
コード例 #9
0
 public virtual long DecodeIntValue(int length, bool signExtend)
 {
     return(Asn1RunTime.DecodeIntValue(this, length, signExtend));
 }
コード例 #10
0
ファイル: Asn1Real.cs プロジェクト: xdios/GostCryptography
        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 ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                }

                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 ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                        }

                        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 ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                        }
                    }
                    try
                    {
                        Value = double.Parse(builder.ToString());
                    }
                    catch (FormatException)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }
                }
                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 ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

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

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

                buffer.TypeCode = RealTypeCode;
            }
        }
コード例 #11
0
 public static int GetBitCount(long ivalue)
 {
     return(Asn1RunTime.GetLongBitCount(ivalue));
 }
コード例 #12
0
 public virtual int GetBitCount()
 {
     return(Asn1RunTime.GetLongBitCount(Value));
 }