Inheritance: Asn1Object
Ejemplo n.º 1
0
        /// <summary>
        ///     Encode an Asn1Numeric directly into the specified outputstream.
        ///     Use a two's complement representation in the fewest number of octets
        ///     possible.
        ///     Can be used to encode INTEGER and ENUMERATED values.
        /// </summary>
        public void encode(Asn1Numeric n, Stream out_Renamed)
        {
            var   octets = new sbyte[8];
            sbyte len;
            var   value_Renamed = n.longValue();
            long  endValue      = value_Renamed < 0 ? -1 : 0;
            var   endSign       = endValue & 0x80;

            for (len = 0; len == 0 || value_Renamed != endValue || (octets[len - 1] & 0x80) != endSign; len++)
            {
                octets[len]     = (sbyte)(value_Renamed & 0xFF);
                value_Renamed >>= 8;
            }

            encode(n.getIdentifier(), out_Renamed);
            out_Renamed.WriteByte((byte)len);  // Length
            for (var i = len - 1; i >= 0; i--)
            {
                // Content
                out_Renamed.WriteByte((byte)octets[i]);
            }
        }
Ejemplo n.º 2
0
		/// <summary> Encode an Asn1Numeric directly into the specified outputstream.
		/// 
		/// Use a two's complement representation in the fewest number of octets
		/// possible.
		/// 
		/// Can be used to encode INTEGER and ENUMERATED values.
		/// </summary>
		public void  encode(Asn1Numeric n, System.IO.Stream out_Renamed)
		{
			sbyte[] octets = new sbyte[8];
			sbyte len;
			long value_Renamed = n.longValue();
			long endValue = (value_Renamed < 0)?- 1:0;
			long endSign = endValue & 0x80;
			
			for (len = 0; len == 0 || value_Renamed != endValue || (octets[len - 1] & 0x80) != endSign; len++)
			{
				octets[len] = (sbyte) (value_Renamed & 0xFF);
				value_Renamed >>= 8;
			}
			
			encode(n.getIdentifier(), out_Renamed);
			out_Renamed.WriteByte((byte) len); // Length
			for (int i = len - 1; i >= 0; i--)
			// Content
				out_Renamed.WriteByte((byte) octets[i]);
			return ;
		}