Пример #1
0
 public override void PerEncode(IAsn1PerEncodingBuffer buffer)
 {
     if (t124Identifier != null && ((Asn1ObjectIdentifier)t124Identifier.GetData()).Value.SequenceEqual(new int[] { 0, 20, 124, 0, 1 }))
     {
         buffer.WriteBytes(new byte[] { 0, 5, 0, 20, 124, 0, 1 });
         connectPDU.PerEncode(buffer);
     }
     else
     {
         base.PerEncode(buffer);
     }
 }
 public override void PerEncode(IAsn1PerEncodingBuffer buffer)
 {
     if (t124Identifier != null && ((Asn1ObjectIdentifier)t124Identifier.GetData()).Value.SequenceEqual(new int[] { 0, 20, 124, 0, 1 }))
     {
         buffer.WriteBytes(new byte[] { 0, 5, 0, 20, 124, 0, 1 });
         connectPDU.PerEncode(buffer);
     }
     else
     {
         base.PerEncode(buffer);
     }
 }
        /// <summary>
        /// Encodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        public override void PerEncode(IAsn1PerEncodingBuffer buffer)
        {
            if (!VerifyConstraints())
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied);
            }
            long offset;
            if (Min == null)
            {
                Debug.Assert(Value != null, "Value != null");
                offset = (long)Value;
            }
            else
            {
                offset = (long)(Value - Min);
            }

            //Ref. X.691: 10.5.2
            if (Min == null || Max == null) //range is equal to null
            {
                if (offset == 0)
                {
                    buffer.WriteByte(0);
                    return;
                }
                //Ref. X.691: 10.3, 10.4
                byte[] result;
                if (Min == null)
                {
                    result = IntegerEncoding(offset);
                }
                else
                {
                    //lowerBound != null && upperBound == null
                    result = NonNegativeBinaryIntegerPerEncode(offset);
                }
                int len = result.Length;
                buffer.WriteByte((byte)len);
                buffer.WriteBytes(result);
                return;
            }
            else
            {
                //lowerBound != null && upperBound != null, range != null, offset should be non-negative
                //Ref. X.691: 10.5
                if (Range == 1)
                {
                    //X.691: 10.5.4
                    return;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    byte[] temp = new byte[] { (byte)offset };
                    buffer.WriteBits(temp, 8 - bitFieldSize, bitFieldSize);
                    return;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    buffer.WriteByte((byte)offset);
                    return;
                }
                else if (Range <= 256 * 256) //10.5.7: c)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset);//Length is either be 1 or 2
                    if (bytes.Length == 1)
                    {
                        buffer.WriteByte(0);
                    }
                    buffer.WriteBytes(bytes);
                    return;
                }
                else //10.5.7: d)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset);
                    Asn1Integer len = new Asn1Integer(bytes.Length, 1, 4);
                    len.PerEncode(buffer);
                    buffer.WriteBytes(bytes);
                    return;
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Encodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        public override void PerEncode(IAsn1PerEncodingBuffer buffer)
        {
            if (!VerifyConstraints())
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied);
            }
            long offset;

            if (Min == null)
            {
                Debug.Assert(Value != null, "Value != null");
                offset = (long)Value;
            }
            else
            {
                offset = (long)(Value - Min);
            }

            //Ref. X.691: 10.5.2
            if (Min == null || Max == null) //range is equal to null
            {
                if (offset == 0)
                {
                    buffer.WriteByte(0);
                    return;
                }
                //Ref. X.691: 10.3, 10.4
                byte[] result;
                if (Min == null)
                {
                    result = IntegerEncoding(offset);
                }
                else
                {
                    //lowerBound != null && upperBound == null
                    result = NonNegativeBinaryIntegerPerEncode(offset);
                }
                int len = result.Length;
                buffer.WriteByte((byte)len);
                buffer.WriteBytes(result);
                return;
            }
            else
            {
                //lowerBound != null && upperBound != null, range != null, offset should be non-negative
                //Ref. X.691: 10.5
                if (Range == 1)
                {
                    //X.691: 10.5.4
                    return;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    byte[] temp = new byte[] { (byte)offset };
                    buffer.WriteBits(temp, 8 - bitFieldSize, bitFieldSize);
                    return;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    buffer.WriteByte((byte)offset);
                    return;
                }
                else if (Range <= 256 * 256)                                  //10.5.7: c)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset); //Length is either be 1 or 2
                    if (bytes.Length == 1)
                    {
                        buffer.WriteByte(0);
                    }
                    buffer.WriteBytes(bytes);
                    return;
                }
                else //10.5.7: d)
                {
                    byte[]      bytes = NonNegativeBinaryIntegerPerEncode(offset);
                    Asn1Integer len   = new Asn1Integer(bytes.Length, 1, 4);
                    len.PerEncode(buffer);
                    buffer.WriteBytes(bytes);
                    return;
                }
            }
        }
        /// <summary>
        /// Encodes the content of the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
        {
            long offset;
            if (Constraints == null || !Constraints.HasMin)
            {
                offset = (long)Value;
            }
            else
            {
                offset = (long)(Value - Constraints.Min);
            }

            //Ref. X.691: 10.5.2
            if (Range == null)
            {
                if (offset == 0)
                {
                    buffer.WriteByte(0);
                    return;
                }
                //Ref. X.691: 10.3, 10.4
                byte[] result;
                if (Constraints == null || !Constraints.HasMin)
                {
                    result = IntegerEncoding(offset);
                }
                else
                {
                    //lowerBound != null && upperBound == null
                    result = NonNegativeBinaryIntegerPerEncode(offset);
                }
                int len = result.Length;
                buffer.WriteByte((byte)len);
                buffer.WriteBytes(result);
                return;
            }
            else
            {
                //lowerBound != null && upperBound != null, range != null, offset should be non-negative
                //Ref. X.691: 10.5
                if (Range == 1)
                {
                    //X.691: 10.5.4
                    return;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    byte[] temp = new byte[] { (byte)offset };
                    buffer.WriteBits(temp, 8 - bitFieldSize, bitFieldSize);
                    return;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    buffer.WriteByte((byte)offset);
                    return;
                }
                else if (Range <= 256 * 256) //10.5.7: c)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset);//Length is either be 1 or 2
                    if (bytes.Length == 1)
                    {
                        buffer.WriteByte(0);
                    }
                    buffer.WriteBytes(bytes);
                    return;
                }
                else //10.5.7: d)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset);
                    Asn1Integer len = new Asn1Integer(bytes.Length, 1, 4);
                    len.PerEncode(buffer);
                    buffer.WriteBytes(bytes);
                    return;
                }
            }
        }
        /// <summary>
        /// Encodes the content of the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
        {
            long offset;

            if (Constraints == null || !Constraints.HasMin)
            {
                offset = (long)Value;
            }
            else
            {
                offset = (long)(Value - Constraints.Min);
            }

            //Ref. X.691: 10.5.2
            if (Range == null)
            {
                if (offset == 0)
                {
                    buffer.WriteByte(0);
                    return;
                }
                //Ref. X.691: 10.3, 10.4
                byte[] result;
                if (Constraints == null || !Constraints.HasMin)
                {
                    result = IntegerEncoding(offset);
                }
                else
                {
                    //lowerBound != null && upperBound == null
                    result = NonNegativeBinaryIntegerPerEncode(offset);
                }
                int len = result.Length;
                buffer.WriteByte((byte)len);
                buffer.WriteBytes(result);
                return;
            }
            else
            {
                //lowerBound != null && upperBound != null, range != null, offset should be non-negative
                //Ref. X.691: 10.5
                if (Range == 1)
                {
                    //X.691: 10.5.4
                    return;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    byte[] temp = new byte[] { (byte)offset };
                    buffer.WriteBits(temp, 8 - bitFieldSize, bitFieldSize);
                    return;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    buffer.WriteByte((byte)offset);
                    return;
                }
                else if (Range <= 256 * 256)                                  //10.5.7: c)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset); //Length is either be 1 or 2
                    if (bytes.Length == 1)
                    {
                        buffer.WriteByte(0);
                    }
                    buffer.WriteBytes(bytes);
                    return;
                }
                else //10.5.7: d)
                {
                    byte[]      bytes = NonNegativeBinaryIntegerPerEncode(offset);
                    Asn1Integer len   = new Asn1Integer(bytes.Length, 1, 4);
                    len.PerEncode(buffer);
                    buffer.WriteBytes(bytes);
                    return;
                }
            }
        }