public static long DecodeIntValue(Asn1DecodeBuffer buffer, int length, bool signExtend) { var num = 0L; if (length > 8) { throw new Exception("Asn1IntegerValueIsTooLarge"); } for (var i = 0; i < length; i++) { var num2 = buffer.ReadByte(); if (num2 < 0) { throw new Exception("Asn1EndOfBufferException"); } if ((i == 0) && signExtend) { num = (num2 > 0x7f) ? -1 : 0; } num = (num * 0x100L) + num2; } return(num); }
public BigInteger DecodeValue(Asn1DecodeBuffer buffer, int length) { var ivalue = new byte[length]; if (length > MaxBigIntLen) { throw new Exception("Asn1 too big integer value"); } for (var i = 0; i < length; ++i) { ivalue[i] = (byte)buffer.ReadByte(); } var integer = new BigInteger(); if (length > 0) { integer.SetData(ivalue); } return(integer); }