BerLib.BerEncoding.DecodeObjectIdentifier C# (CSharp) Метод

DecodeObjectIdentifier() публичный статический Метод

public static DecodeObjectIdentifier ( IBerInput input, int length ) : int[]
input IBerInput
length int
Результат int[]
        public static int[] DecodeObjectIdentifier(IBerInput input, int length)
        {
            var values = new List<int>();
             int subidentifier = 0;
             uint bytesRead = 0;

             while(bytesRead++ < length)
             {
            byte uByte = input.ReadByte();

            subidentifier = ((subidentifier << 7) | (uByte & 0x7F));

            if((uByte & 0x80) == 0)
            {
               if(values.Count > 0)
               {
                  values.Add(subidentifier);
               }
               else
               {
                  values.Add(subidentifier / 40);
                  values.Add(subidentifier % 40);
               }

               subidentifier = 0;
            }
             }

             return values.ToArray();
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Decodes the value of the current TLV as an OBJECT IDENTIFIER represented
        /// as an integer array, each integer containing one sub-identifier.
        /// Throws an exception in case of a format mismatch.
        /// </summary>
        /// <returns>Integer array containing the OBJECT IDENTIFIER value of the current TLV.</returns>
        public int[] GetObjectIdentifier()
        {
            if (IsContainer || Length == 0 || Value == null)
            {
                ThrowError(209, "Invalid ObjectIdentifier encoding");
            }

            Debug.Assert(Value != null || Length == 0);
            Debug.Assert(Type == BerType.ObjectIdentifier || BerType.IsApplicationDefined(Type));

            var input = new BerMemoryInput(Value);

            return(BerEncoding.DecodeObjectIdentifier(input, Length));
        }