Beispiel #1
0
        public static long DecodeIntValue(Asn1DecodeBuffer buffer, int length, bool signExtend)
        {
            var num = 0L;

            if (length > 8)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1IntegerValueIsTooLarge);
            }

            for (var i = 0; i < length; i++)
            {
                var num2 = buffer.ReadByte();

                if (num2 < 0)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                }

                if ((i == 0) && signExtend)
                {
                    num = (num2 > 0x7f) ? -1 : 0;
                }

                num = (num * 0x100L) + num2;
            }

            return(num);
        }
        public static long DecodeIntValue(Asn1DecodeBuffer buffer, int length, bool signExtend)
        {
            var num = 0L;

            if (length > 8)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1IntegerValueIsTooLarge);
            }

            for (var i = 0; i < length; i++)
            {
                var num2 = buffer.ReadByte();

                if (num2 < 0)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                }

                if ((i == 0) && signExtend)
                {
                    num = (num2 > 0x7f) ? -1 : 0;
                }

                num = (num * 0x100L) + num2;
            }

            return num;
        }
Beispiel #3
0
        private static void ReadSegment(Asn1DecodeBuffer buffer, StringBuilder sb, int len)
        {
            if ((len % 2) != 0)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
            }

            while (len > 0)
            {
                var num = buffer.Read();

                if (num == -1)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                }

                var num2 = num * 0x100;
                len--;
                num = buffer.Read();

                if (num == -1)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                }

                num2 += num;
                len--;
                sb.Append((char)num2);
            }
        }
        public BigInteger DecodeValue(Asn1DecodeBuffer buffer, int length)
        {
            var ivalue = new byte[length];

            if (length > MaxBigIntLen)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1TooBigIntegerValue, length);
            }

            for (var i = 0; i < length; ++i)
            {
                ivalue[i] = (byte)buffer.ReadByte();
            }

            var integer = new BigInteger();

            if (length > 0)
            {
                integer.SetData(ivalue);
            }

            return(integer);
        }
        public BigInteger DecodeValue(Asn1DecodeBuffer buffer, int length)
        {
            var ivalue = new byte[length];

            if (length > MaxBigIntLen)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1TooBigIntegerValue, length);
            }

            for (var i = 0; i < length; ++i)
            {
                ivalue[i] = (byte)buffer.ReadByte();
            }

            var integer = new BigInteger();

            if (length > 0)
            {
                integer.SetData(ivalue);
            }

            return integer;
        }
        private static void ReadSegment(Asn1DecodeBuffer buffer, StringBuilder sb, int len)
        {
            if ((len % 2) != 0)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
            }

            while (len > 0)
            {
                var num = buffer.Read();

                if (num == -1)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                }

                var num2 = num * 0x100;
                len--;
                num = buffer.Read();

                if (num == -1)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                }

                num2 += num;
                len--;
                sb.Append((char)num2);
            }
        }