Ejemplo n.º 1
0
        public static int GetTagLength(BerTag tag)
        {
            var number = tag.Number;

            if (number < 0x1F)
            {
                return(1);
            }

            return(1 + GetMultiByteLongLength(number));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        // ====================================================================
        //
        // 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);
        }
Ejemplo n.º 5
0
        // ====================================================================
        //
        // 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);
        }
Ejemplo n.º 6
0
 static void EncodeHeader(IBerOutput output, BerTag tag, int length)
 {
     BerEncoding.EncodeTag(output, tag);
     BerEncoding.EncodeLength(output, length);
 }