/// <summary> /// Decodes the value of the current TLV a 64bit integer. /// Throws an exception in case of a format mismatch. /// </summary> /// <returns>The integer value of the current TLV.</returns> public long GetLong() { if (IsContainer || Length == 0 || Value == null) { ThrowError(203, "Invalid Integer encoding"); } Debug.Assert(Value != null || Length == 0); Debug.Assert(Type == BerType.Integer || BerType.IsApplicationDefined(Type)); var input = new BerMemoryInput(Value); return(BerEncoding.DecodeLong(input, Length)); }
public static object[] Decode(string format, IList <byte> data) { var input = new BerMemoryInput(data); var objects = new List <object>(); for (int charIndex = 0; charIndex < format.Length; charIndex++) { var ch = format[charIndex]; switch (ch) { case '{': DecodeHeader(input, TypeTags.Sequence); break; case '}': { if (input.ReadByte() != 0) { throw new BerException(4002, "Expected terminator"); } if (input.ReadByte() != 0) { throw new BerException(4002, "Expected terminator"); } break; } case 'b': { DecodeHeader(input, TypeTags.Boolean); objects.Add(BerEncoding.DecodeBoolean(input)); break; } case 'i': case 'd': { var valueLength = DecodeHeader(input, TypeTags.Integer); objects.Add(BerEncoding.DecodeInteger(input, valueLength)); break; } case 'l': case 't': { var valueLength = DecodeHeader(input, TypeTags.Integer); objects.Add(BerEncoding.DecodeLong(input, valueLength)); break; } case 's': { var valueLength = DecodeHeader(input, TypeTags.UTF8String); objects.Add(BerEncoding.DecodeUtf8String(input, valueLength)); break; } case 'y': { var valueLength = DecodeHeader(input, TypeTags.OctetString); objects.Add(BerEncoding.DecodeByteArray(input, valueLength)); break; } case 'f': case 'r': { var valueLength = DecodeHeader(input, TypeTags.Real); objects.Add(BerEncoding.DecodeReal(input, valueLength)); break; } case 'o': { var valueLength = DecodeHeader(input, TypeTags.RelativeOid); objects.Add(BerEncoding.DecodeRelativeOid(input, valueLength)); break; } case 'g': { var valueLength = DecodeHeader(input, TypeTags.GeneralizedTime); objects.Add(BerEncoding.DecodeGeneralizedTime(input, valueLength)); break; } } } return(objects.ToArray()); }