Exemplo n.º 1
0
 public void Write(BerTag tag, bool value)
 {
     WriteOuterHeader(tag, 3);
     BerEncoding.EncodeTag(_output, new BerTag(BerType.Boolean));
     BerEncoding.EncodeLength(_output, 1);
     BerEncoding.EncodeBoolean(_output, value);
 }
Exemplo n.º 2
0
        internal override int Update()
        {
            var output      = new BerMemoryOutput();
            var implicitTag = new BerTag(BerClass.Universal, BerTypeNumber, true);

            var childrenLength = 0;

            foreach (var child in this)
            {
                childrenLength += child.IsDirty
                              ? child.Update()
                              : child.EncodedLength;
            }

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, BerDefinitions.IndefiniteLength);

            BerEncoding.EncodeTag(output, implicitTag);
            BerEncoding.EncodeLength(output, BerDefinitions.IndefiniteLength);

            _encodedFrameHeader = output.ToArray();
            EncodedLength       = childrenLength + _encodedFrameHeader.Length + BerEncoding.IndefiniteLengthTerminator.Length;

            return(EncodedLength);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Pre-encodes the BER header and returns the byte length of the encoded node.
        /// Overridden to recursively pre-encode all descendants.
        /// </summary>
        /// <returns>The length of the encoded node.</returns>
        internal override int Update()
        {
            var output      = new BerMemoryOutput();
            var implicitTag = BerType.IsApplicationDefined(BerTypeNumber)
                           ? new BerTag(BerClass.Application, BerTypeNumber & ~BerType.ApplicationFlag, true)
                           : new BerTag(BerClass.Universal, BerTypeNumber, true);

            _childrenLength = 0;

            foreach (var child in _nodes)
            {
                _childrenLength += child.IsDirty
                               ? child.Update()
                               : child.EncodedLength;
            }

            var implicitLength = _childrenLength + BerEncoding.GetHeaderLength(implicitTag, _childrenLength);

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, implicitLength);

            BerEncoding.EncodeTag(output, implicitTag);
            BerEncoding.EncodeLength(output, _childrenLength);

            _encodedHeader = output.ToArray();
            EncodedLength  = _childrenLength + _encodedHeader.Length;

            return(EncodedLength);
        }
Exemplo n.º 4
0
        public void Write(BerTag tag, long value)
        {
            var valueLength = BerEncoding.GetLongLength(value);

            WriteOuterHeader(tag, valueLength + 2);
            BerEncoding.EncodeTag(_output, new BerTag(BerType.Integer));
            BerEncoding.EncodeLength(_output, valueLength);
            BerEncoding.EncodeLong(_output, value, (int)valueLength);
        }
Exemplo n.º 5
0
        public void Write(BerTag tag, byte[] value)
        {
            var valueLength = value.Length;
            var innerTag    = new BerTag(BerType.OctetString);

            WriteOuterHeader(tag, valueLength + BerEncoding.GetHeaderLength(innerTag, valueLength));
            BerEncoding.EncodeTag(_output, innerTag);
            BerEncoding.EncodeLength(_output, valueLength);
            _output.WriteBytes(value);
        }
Exemplo n.º 6
0
        public void WriteRelativeOid(BerTag tag, int[] value)
        {
            var innerTag    = new BerTag(BerType.RelativeOid);
            var valueLength = BerEncoding.GetRelativeOidLength(value);

            WriteOuterHeader(tag, valueLength + BerEncoding.GetHeaderLength(innerTag, valueLength));
            BerEncoding.EncodeTag(_output, innerTag);
            BerEncoding.EncodeLength(_output, valueLength);
            BerEncoding.EncodeRelativeOid(_output, value);
        }
Exemplo n.º 7
0
        public void Write(BerTag tag, double value)
        {
            var valueOutput = new BerMemoryOutput();
            var valueLength = BerEncoding.EncodeReal(valueOutput, value);

            WriteOuterHeader(tag, valueLength + 2);
            BerEncoding.EncodeTag(_output, new BerTag(BerType.Real));
            BerEncoding.EncodeLength(_output, valueLength);
            _output.WriteBytes(valueOutput.Memory);
        }
Exemplo n.º 8
0
        public void Write(BerTag tag, string value)
        {
            var valueOutput = new BerMemoryOutput();
            var valueLength = BerEncoding.EncodeUtf8String(valueOutput, value);
            var innerTag    = new BerTag(BerType.UTF8String);

            WriteOuterHeader(tag, valueLength + BerEncoding.GetHeaderLength(innerTag, valueLength));
            BerEncoding.EncodeTag(_output, innerTag);
            BerEncoding.EncodeLength(_output, valueLength);
            _output.WriteBytes(valueOutput.Memory);
        }
Exemplo n.º 9
0
        internal override int Update()
        {
            var output = new BerMemoryOutput();

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, 2);
            BerEncoding.EncodeTag(output, new BerTag(BerTypeNumber));
            BerEncoding.EncodeLength(output, 0);

            Encoded       = output.ToArray();
            EncodedLength = Encoded.Length;

            return(EncodedLength);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Pre-encodes the BER header and returns the byte length of the encoded node.
        /// Overriden to encode the entire TLTLV
        /// </summary>
        /// <returns>The length of the encoded node.</returns>
        internal override int Update()
        {
            var output      = new BerMemoryOutput();
            var valueLength = BerEncoding.GetLongLength(Value);

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, valueLength + 2);

            BerEncoding.EncodeTag(output, new BerTag(BerType.Integer));
            BerEncoding.EncodeLength(output, valueLength);
            BerEncoding.EncodeLong(output, Value, valueLength);

            Encoded       = output.ToArray();
            EncodedLength = Encoded.Length;
            return(EncodedLength);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Pre-encodes the BER header and returns the byte length of the encoded node.
        /// Overriden to encode the entire TLTLV
        /// </summary>
        /// <returns>The length of the encoded node.</returns>
        internal override int Update()
        {
            var output = new BerMemoryOutput();

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, 3);

            BerEncoding.EncodeTag(output, new BerTag(BerType.Boolean));
            BerEncoding.EncodeLength(output, 1);
            BerEncoding.EncodeBoolean(output, Value);

            Encoded       = output.ToArray();
            EncodedLength = Encoded.Length;

            return(EncodedLength);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Pre-encodes the BER header and returns the byte length of the encoded node.
        /// Overriden to encode the entire TLTLV
        /// </summary>
        /// <returns>The length of the encoded node.</returns>
        internal override int Update()
        {
            var output         = new BerMemoryOutput();
            var tagImplicit    = new BerTag(BerType.RelativeOid);
            var valueLength    = BerEncoding.GetRelativeOidLength(Value);
            var implicitLength = valueLength + BerEncoding.GetHeaderLength(tagImplicit, valueLength);

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, implicitLength);

            BerEncoding.EncodeTag(output, tagImplicit);
            BerEncoding.EncodeLength(output, valueLength);

            Encoded = output.ToArray();

            EncodedLength = valueLength + Encoded.Length;
            return(EncodedLength);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Pre-encodes the BER header and returns the byte length of the encoded node.
        /// Overriden to encode the entire TLTLV
        /// </summary>
        /// <returns>The length of the encoded node.</returns>
        internal override int Update()
        {
            var output      = new BerMemoryOutput();
            var arrayLength = Value.Length;

            var tagImplicit    = new BerTag(BerType.OctetString);
            var implicitLength = (arrayLength + BerEncoding.GetHeaderLength(tagImplicit, arrayLength));

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, implicitLength);

            BerEncoding.EncodeTag(output, tagImplicit);
            BerEncoding.EncodeLength(output, arrayLength);

            Encoded       = output.ToArray();
            EncodedLength = arrayLength + Encoded.Length;
            return(EncodedLength);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Pre-encodes the BER header and returns the byte length of the encoded node.
        /// </summary>
        /// <returns>The length of the encoded node.</returns>
        internal override int Update()
        {
            var output       = new BerMemoryOutput();
            var stringLength = BerEncoding.GetUtf8StringLength(Value);

            var tagImplicit    = new BerTag(BerType.UTF8String);
            var implicitLength = (stringLength + BerEncoding.GetHeaderLength(tagImplicit, stringLength));

            BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, implicitLength);

            BerEncoding.EncodeTag(output, tagImplicit);
            BerEncoding.EncodeLength(output, stringLength);

            Encoded       = output.ToArray();
            EncodedLength = stringLength + Encoded.Length;
            return(EncodedLength);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Pre-encodes the BER header and returns the byte length of the encoded node.
        /// Overriden to encode the entire TLTLV
        /// </summary>
        /// <returns>The length of the encoded node.</returns>
        internal override int Update()
        {
            var output = new BerMemoryOutput();

            int tagLength, innerLength = 0, valueLength;

            tagLength = BerEncoding.EncodeTag(output, Tag.ToContainer());
            BerEncoding.EncodeLength(output, 0);

            innerLength += BerEncoding.EncodeTag(output, new BerTag(BerType.Real));
            innerLength += BerEncoding.EncodeLength(output, 0);
            innerLength += valueLength = BerEncoding.EncodeReal(output, Value);

            Encoded       = output.ToArray();
            EncodedLength = Encoded.Length;

            Encoded[tagLength]     = (byte)innerLength; // fix outer length
            Encoded[tagLength + 2] = (byte)valueLength; // fix inner length
            return(EncodedLength);
        }
Exemplo n.º 16
0
 void WriteOuterHeader(BerTag tag, int length)
 {
     BerEncoding.EncodeTag(_output, tag.ToContainer());
     BerEncoding.EncodeLength(_output, length);
 }
Exemplo n.º 17
0
 public void WriteContainerBegin(BerTag tag, uint type)
 {
     WriteOuterHeader(tag, BerDefinitions.IndefiniteLength);
     BerEncoding.EncodeTag(_output, new BerTag(type, true));
     BerEncoding.EncodeLength(_output, BerDefinitions.IndefiniteLength);
 }