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); }
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); }
/// <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); }
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); }
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); }
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); }
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); }
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); }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
void WriteOuterHeader(BerTag tag, int length) { BerEncoding.EncodeTag(_output, tag.ToContainer()); BerEncoding.EncodeLength(_output, length); }
public void WriteContainerBegin(BerTag tag, uint type) { WriteOuterHeader(tag, BerDefinitions.IndefiniteLength); BerEncoding.EncodeTag(_output, new BerTag(type, true)); BerEncoding.EncodeLength(_output, BerDefinitions.IndefiniteLength); }