internal override void Encode(
            DerOutputStream derOut)
        {
            OidTokenizer    tok  = new OidTokenizer(identifier);
            MemoryStream    bOut = new MemoryStream();
            DerOutputStream dOut = new DerOutputStream(bOut);

            string token = tok.NextToken();
            int    first = int.Parse(token);

            token = tok.NextToken();
            int second = int.Parse(token);

            WriteField(bOut, first * 40 + second);

            while (tok.HasMoreTokens)
            {
                token = tok.NextToken();
                if (token.Length < 18)
                {
                    WriteField(bOut, Int64.Parse(token));
                }
                else
                {
                    WriteField(bOut, new BigInteger(token));
                }
            }

            dOut.Close();

            derOut.WriteEncoded(Asn1Tags.ObjectIdentifier, bOut.ToArray());
        }
Exemple #2
0
        /*
         * A note on the implementation:
         * <p>
         * As Der requires the constructed, definite-length model to
         * be used for structured types, this varies slightly from the
         * ASN.1 descriptions given. Rather than just outputing Sequence,
         * we also have to specify Constructed, and the objects length.
         */
        internal override void Encode(
            DerOutputStream derOut)
        {
            // TODO Intermediate buffer could be avoided if we could calculate expected length
            MemoryStream    bOut = new MemoryStream();
            DerOutputStream dOut = new DerOutputStream(bOut);

            foreach (Asn1Encodable obj in this)
            {
                dOut.WriteObject(obj);
            }

            dOut.Close();

            byte[] bytes = bOut.ToArray();

            derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, bytes);
        }