Renci.SshNet.Common.DerData.ReadInteger C# (CSharp) Метод

ReadInteger() публичный Метод

Reads next int data type from internal buffer.
public ReadInteger ( ) : int
Результат int
        public int ReadInteger()
        {
            var type = ReadByte();
            if (type != Integer)
                throw new InvalidOperationException("Invalid data type, INTEGER(02) is expected.");

            var length = ReadLength();

            var data = ReadBytes(length);

            if (length > 4)
                throw new InvalidOperationException("Integer type cannot occupy more then 4 bytes");

            var result = 0;
            var shift = (length - 1) * 8;
            for (var i = 0; i < length; i++)
            {
                result |= data[i] << shift;
                shift -= 8;
            }

            //return (int)(data[0] << 56 | data[1] << 48 | data[2] << 40 | data[3] << 32 | data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]);

            return result;
        }

Usage Example

Пример #1
0
 public void ReadIntegerTest()
 {
     DerData target = new DerData(); // TODO: Initialize to an appropriate value
     int expected = 0; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.ReadInteger();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }