Example #1
0
 /// <summary>
 /// Encodes the content of the object by PER.
 /// </summary>
 /// <param name="buffer">A buffer to which the encoding result will be written.</param>
 /// <remarks>Length is included.</remarks>
 protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
 {
     Asn1StandardProcedure.PerEncodeArray(buffer, Elements, (encodingBuffer, obj) =>
     {
         obj.PerEncode(encodingBuffer);
     },
                                          Constraint != null && Constraint.HasMinSize ? Constraint.MinSize : (long?)null, Constraint != null && Constraint.HasMaxSize ? Constraint.MaxSize : (long?)null);
 }
Example #2
0
 /// <summary>
 /// Decodes the content of the object by PER.
 /// </summary>
 /// <param name="buffer">A buffer that contains a PER encoding result.</param>
 /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
 /// <remarks>Length is included.</remarks>
 protected override void ValuePerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
 {
     Elements = Asn1StandardProcedure.PerDecodeArray(buffer, decodingBuffer =>
     {
         T curObj = new T();
         curObj.PerDecode(buffer);
         return(curObj);
     },
                                                     Constraint != null && Constraint.HasMinSize ? Constraint.MinSize : (long?)null, Constraint != null && Constraint.HasMaxSize ? Constraint.MaxSize : (long?)null);
 }
Example #3
0
 /// <summary>
 /// Encodes the content of the object by PER.
 /// </summary>
 /// <param name="buffer">A buffer to which the encoding result will be written.</param>
 /// <remarks>Length is included.</remarks>
 protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
 {
     Asn1StandardProcedure.PerEncodeArray(buffer, Value.ToCharArray(),
                                          (encodingBuffer, b) =>
     {
         byte[] result = Encoding.BigEndianUnicode.GetBytes("" + b);
         encodingBuffer.WriteBytes(result);
     }
                                          , Constraint != null && Constraint.HasMinSize ? Constraint.MinSize : (long?)null, Constraint != null && Constraint.HasMaxSize ? Constraint.MaxSize : (long?)null,
                                          true);
 }
Example #4
0
 /// <summary>
 /// Decodes the object by PER.
 /// </summary>
 /// <param name="buffer">A buffer that contains a PER encoding result.</param>
 /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
 /// <remarks>Length is included.</remarks>
 protected override void ValuePerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
 {
     char[] result = Asn1StandardProcedure.PerDecodeArray <char>(buffer,
                                                                 decodingBuffer =>
     {
         byte[] encodingResult = buffer.ReadBytes(2);
         string s = Encoding.BigEndianUnicode.GetString(encodingResult);
         return(s[0]);
     },
                                                                 Constraint != null && Constraint.HasMinSize ? Constraint.MinSize : (long?)null, Constraint != null && Constraint.HasMaxSize ? Constraint.MaxSize : (long?)null,
                                                                 true);
     Value = new string(result);
 }
Example #5
0
        /// <summary>
        /// Check if tag from buffer is match with input Asn1Tag
        /// </summary>
        /// <param name="buffer">decode buffer</param>
        /// <param name="tag">compare Asn1Tag</param>
        /// <param name="length">Tag Length</param>
        /// <param name="IsForward">If true Postion + 1, otherwise not change Postion</param>
        /// <returns>Tag from Buffer is match with input Tag</returns>
        public virtual bool IsTagMatch(IAsn1DecodingBuffer buffer, Asn1Tag tag, out int length, bool IsForward = false)
        {
            length = 0;
            if (buffer.IsNomoreData())
            {
                return(false);
            }

            byte tagByte       = Asn1StandardProcedure.GetEncodeTag(tag);
            byte bufferTagByte = IsForward ? buffer.ReadByte() : buffer.PeekByte();

            length = IsForward ? 1 : 0;
            return(tagByte == bufferTagByte);
        }
        /// <summary>
        /// Encodes the content of the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        /// <remarks>Length is included.</remarks>
        protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
        {
            if (Value[0] * 40 + Value[1] >= 128)
            {
                throw new NotImplementedException("Ojbect Identifier with first element greater than 127 is not implemented.");
                //Len will be minus 1 while encoding.
            }
            var res = EncodeIdentifier(Value);

            Asn1StandardProcedure.PerEncodeArray <byte>(buffer, res,
                                                        (encodingBuffer, b) =>
            {
                encodingBuffer.WriteByte(b);
            });
        }
 /// <summary>
 /// Decodes the content of the object by PER.
 /// </summary>
 /// <param name="buffer">A buffer that contains a PER encoding result.</param>
 /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
 /// <remarks>Length is included.</remarks>
 protected override void ValuePerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
 {
     byte[] res = Asn1StandardProcedure.PerDecodeArray(buffer, decodingBuffer => (decodingBuffer.ReadByte()));
     Value = DecodeIdentifiers(res);
 }
 /// <summary>
 /// Decodes a tag from the buffer.
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="tag"></param>
 /// <returns>The number of the bytes consumed in the buffer to decode the tag.</returns>
 /// <remarks>Override this method in a user-defined class only if the procedure is not applicable in some special scenarios.</remarks>
 protected virtual int TagBerDecode(IAsn1DecodingBuffer buffer, out Asn1Tag tag)
 {
     return(Asn1StandardProcedure.TagBerDecode(buffer, out tag));
 }
 /// <summary>
 /// Encodes a tag to the buffer.
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="tag"></param>
 /// <returns>The length of the encoding result.</returns>
 /// <remarks>Override this method in a user-defined class only if the procedure is not applicable in some special scenarios.</remarks>
 protected virtual int TagBerEncode(IAsn1BerEncodingBuffer buffer, Asn1Tag tag)
 {
     return(Asn1StandardProcedure.TagBerEncode(buffer, tag));
 }
 /// <summary>
 /// Reads/decodes a length from the buffer.
 /// </summary>
 /// <param name="buffer">A buffer that stores a BER encoding result.</param>
 /// <param name="decodedLength">The decoded length will be retrieved by this param.</param>
 /// <returns>The number of the bytes consumed in the buffer to decode the length.</returns>
 /// <remarks>
 /// This method are implementd by Asn1StandardBerProcedure.LengthBerDecode.
 /// Override this method in a user-defined class only if the standard procedure is not applicable in some special scenarios.
 /// </remarks>
 protected virtual int LengthBerDecode(IAsn1DecodingBuffer buffer, out int decodedLength)
 {
     return(Asn1StandardProcedure.LengthBerDecode(buffer, out decodedLength));
 }
 /// <summary>
 /// Encodes a length to the buffer.
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="length">The length to be written to the buffer.</param>
 /// <returns>The length of "the encoded length's encoding result".</returns>
 /// <remarks>
 /// This method are implementd by Asn1StandardBerProcedure.LengthBerEncode.
 /// Override this method in a user-defined class only if the standard procedure is not applicable in some special scenarios.
 /// </remarks>
 protected virtual int LengthBerEncode(IAsn1BerEncodingBuffer buffer, int length)
 {
     return(Asn1StandardProcedure.LengthBerEncode(buffer, length));
 }