public static int GetTagLength(BerTag tag) { var number = tag.Number; if (number < 0x1F) { return(1); } return(1 + GetMultiByteLongLength(number)); }
public static int GetHeaderLength(BerTag tag, int length) { int result = GetTagLength(tag); if (length <= 0x7F || length == BerDefinitions.IndefiniteLength) { return(result + 1); } return(result + 1 + GetIntegerLength(length)); }
static int DecodeHeader(IBerInput input, BerTag expectedTag) { var tag = BerEncoding.DecodeTag(input); if (tag != expectedTag) { throw new BerException(4001, String.Format("Expected tag {0}, found tag {1}", tag, expectedTag)); } return(BerEncoding.DecodeLength(input)); }
// ==================================================================== // // Decode functions // // ==================================================================== #region DecodeFunctions public static BerTag DecodeTag(IBerInput input) { var tagByte = input.ReadByte(); var tag = new BerTag((byte)(tagByte & 0xE0), (uint)(tagByte & 0x1F)); if (tag.Number == 0x1F) { tag.Number = DecodeMultiByteInteger(input); } return(tag); }
// ==================================================================== // // Encode functions // all return the number of bytes in the // encoded result. // // ==================================================================== #region Encode Functions public static int EncodeTag(IBerOutput output, BerTag tag) { var number = tag.Number; var size = 1; tag.Preamble &= 0xE0; if (number < 0x1F) { output.WriteByte((byte)(tag.Preamble | (number & 0x1F))); } else { output.WriteByte((byte)(tag.Preamble | 0x1F)); size += EncodeMultiByteInteger(output, number); } return(size); }
static void EncodeHeader(IBerOutput output, BerTag tag, int length) { BerEncoding.EncodeTag(output, tag); BerEncoding.EncodeLength(output, length); }