Esempio n. 1
0
        /// <summary>
        /// Creates a default instance of <strong>Asn1Builder</strong> class from existing ASN.1-encoded data.
        /// </summary>
        /// <param name="rawData">ASN.1-encoded data to initialize the builder from.</param>
        /// <returns>ASN.1 Builder.</returns>
        public static Asn1Builder Create(Byte[] rawData)
        {
            var builder = new Asn1Builder();

            builder._rawData.AddRange(rawData);

            return(builder);
        }
        /// <summary>
        /// Adds explicitly tagged type. Explicit (EXPLICIT OPTIONAL) must have at least one primitive or constructed nested type.
        /// </summary>
        /// <param name="explicitTag">
        ///     Explicit tag number. This number equals to tag number in square brackets in ASN module definition of EXPLICIT.
        /// </param>
        /// <param name="selector">Lambda expression to fill nested content.</param>
        /// <exception cref="ArgumentNullException">
        ///     <strong>selector</strong> parameter is null.
        /// </exception>
        /// <returns>Current instance with added value.</returns>
        public Asn1Builder AddExplicit(Byte explicitTag, Func <Asn1Builder, Asn1Builder> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }
            Asn1Builder b = selector(new Asn1Builder());

            _rawData.AddRange(Asn1Utils.Encode(b._rawData.ToArray(), (Byte)(0xa0 + explicitTag)));
            return(this);
        }
        /// <summary>
        /// Adds constructed SET.
        /// </summary>
        /// <param name="selector">Lambda expression to fill nested content.</param>
        /// <exception cref="ArgumentNullException">
        ///     <strong>selector</strong> parameter is null.
        /// </exception>
        /// <returns>Current instance with added value.</returns>
        public Asn1Builder AddSet(Func <Asn1Builder, Asn1Builder> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }
            Asn1Builder b = selector(new Asn1Builder());

            _rawData.AddRange(Asn1Utils.Encode(b._rawData.ToArray(), 0x31));
            return(this);
        }
        /// <summary>
        /// Adds constructed octet string.
        /// </summary>
        /// <param name="selector">Lambda expression to fill nested content.</param>
        /// <exception cref="ArgumentNullException">
        ///     <strong>selector</strong> parameter is null.
        /// </exception>
        /// <returns>Current instance with added value.</returns>
        /// <remarks>
        ///     In the current implementation, constructed OCTET_STRING is encoded using primitive form.
        /// </remarks>
        public Asn1Builder AddOctetString(Func <Asn1Builder, Asn1Builder> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }
            Asn1Builder b = selector(new Asn1Builder());

            _rawData.AddRange(Asn1Utils.Encode(b._rawData.ToArray(), (Byte)Asn1Type.OCTET_STRING));
            return(this);
        }
        /// <summary>
        /// Adds constructed bit string.
        /// </summary>
        /// <param name="selector">Lambda expression to fill nested content.</param>
        /// <exception cref="ArgumentNullException">
        ///     <strong>selector</strong> parameter is null.
        /// </exception>
        /// <returns>Current instance with added value.</returns>
        /// <remarks>
        ///     In the current implementation, constructed BIT_STRING is encoded using primitive form.
        /// </remarks>
        public Asn1Builder AddBitString(Func <Asn1Builder, Asn1Builder> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }
            Asn1Builder b = selector(new Asn1Builder());

            _rawData.AddRange(new Asn1BitString(b._rawData.ToArray(), 0).RawData);
            return(this);
        }
 Asn1Builder(Asn1Builder builder)
 {
     _rawData = new List <Byte>(builder._rawData);
 }