System.Security.Cryptography.DerEncoder.EncodeRid C# (CSharp) Method

EncodeRid() private static method

private static EncodeRid ( List encodedData, System.Numerics.BigInteger &rid ) : void
encodedData List
rid System.Numerics.BigInteger
return void
        private static void EncodeRid(List<byte> encodedData, ref BigInteger rid)
        {
            BigInteger divisor = new BigInteger(128);
            BigInteger unencoded = rid;

            // The encoding is 7 bits of value and the 8th bit signifies "keep reading".
            // So, for the input 1079 (0b0000 0100 0011 0111) the partitioning is
            // 00|00 0100 0|011 0111, and the leading two bits are ignored.
            // Therefore the encoded is 0b1000 1000 0011 0111 = 0x8837

            Stack<byte> littleEndianBytes = new Stack<byte>();
            byte continuance = 0;

            do
            {
                BigInteger remainder;
                unencoded = BigInteger.DivRem(unencoded, divisor, out remainder);

                byte octet = (byte)remainder;
                octet |= continuance;

                // Any remaining (preceding) bytes need the continuance bit set.
                continuance = 0x80;
                littleEndianBytes.Push(octet);
            }
            while (unencoded != BigInteger.Zero);

            encodedData.AddRange(littleEndianBytes);
        }