WriteEncoded() private method

private WriteEncoded ( int tag, byte bytes ) : void
tag int
bytes byte
return void
Exemplo n.º 1
0
        internal override void Encode(
			DerOutputStream derOut)
        {
            if (parsed)
            {
                base.Encode(derOut);
            }
            else
            {
                derOut.WriteEncoded(Asn1Tags.Set | Asn1Tags.Constructed, encoded);
            }
        }
Exemplo n.º 2
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     if (derOut is Asn1OutputStream || derOut is BerOutputStream)
     {
         derOut.WriteEncoded(Asn1Tags.BitString, (byte)mPadBits, mData);
     }
     else
     {
         base.Encode(derOut);
     }
 }
		internal override void Encode(
			DerOutputStream derOut)
		{
			lock (this)
			{
				if (encoded == null)
				{
					base.Encode(derOut);
				}
				else
				{
					derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, encoded);
				}
			}
		}
Exemplo n.º 4
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)
        {
            MemoryStream bOut = new MemoryStream();
            DerOutputStream dOut = new DerOutputStream(bOut);

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

            dOut.Close();

            byte[] bytes = bOut.ToArray();

            derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, bytes);
        }
		/*
		 * 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.Dispose();

			byte[] bytes = bOut.ToArray();

			derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, bytes);
		}
Exemplo n.º 6
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.UtcTime, GetOctets());
 }
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.Enumerated, bytes);
 }
Exemplo n.º 8
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(0x19, this.mString);
 }
Exemplo n.º 9
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.Integer, bytes);
 }
Exemplo n.º 10
0
 internal static void Encode(DerOutputStream derOut, byte[] bytes, int offset, int length)
 {
     derOut.WriteEncoded(4, bytes, offset, length);
 }
Exemplo n.º 11
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.Enumerated, bytes);
 }
Exemplo n.º 12
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.Null, zeroBytes);
 }
Exemplo n.º 13
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(2, this.bytes);
 }
Exemplo n.º 14
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(12, Encoding.UTF8.GetBytes(this.str));
 }
Exemplo n.º 15
0
        internal override void Encode(
			DerOutputStream derOut)
		{
            if (mPadBits > 0)
            {
                int last = mData[mData.Length - 1];
                int mask = (1 << mPadBits) - 1;
                int unusedBits = last & mask;

                if (unusedBits != 0)
                {
                    byte[] contents = Arrays.Prepend(mData, (byte)mPadBits);

                    /*
                     * X.690-0207 11.2.1: Each unused bit in the final octet of the encoding of a bit string value shall be set to zero.
                     */
                    contents[contents.Length - 1] = (byte)(last ^ unusedBits);

                    derOut.WriteEncoded(Asn1Tags.BitString, contents);
                    return;
                }
            }

            derOut.WriteEncoded(Asn1Tags.BitString, (byte)mPadBits, mData);
		}
Exemplo n.º 16
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(tag, data);
 }
Exemplo n.º 17
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(0x1c, this.str);
 }
Exemplo n.º 18
0
        internal override void Encode(
			DerOutputStream derOut)
        {
            derOut.WriteEncoded(Asn1Tags.Application | tag, octets);
        }
Exemplo n.º 19
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(1, new byte[1] {
         value
     });
 }
Exemplo n.º 20
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.Utf8String, Encoding.UTF8.GetBytes(str));
 }
Exemplo n.º 21
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(isConstructed ? Asn1Tags.Constructed : 0, tag, data);
 }
Exemplo n.º 22
0
        internal override void Encode(
            DerOutputStream derOut)
        {
            byte[] bytes = new byte[GetBytes().Length + 1];

            bytes[0] = (byte) PadBits;
            Array.Copy(GetBytes(), 0, bytes, 1, bytes.Length - 1);

            derOut.WriteEncoded(Asn1Tags.BitString, bytes);
        }
Exemplo n.º 23
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(28, str);
 }
Exemplo n.º 24
0
		internal override void Encode(
            DerOutputStream derOut)
        {
            derOut.WriteEncoded(Asn1Tags.UniversalString, this.str);
        }
Exemplo n.º 25
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.ObjectIdentifier, GetBody());
 }
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.Application | tag, octets);
 }
Exemplo n.º 27
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(12, Encoding.get_UTF8().GetBytes(str));
 }
Exemplo n.º 28
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.OctetString, str);
 }
Exemplo n.º 29
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.UniversalString, this.str);
 }
Exemplo n.º 30
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.Integer, bytes);
 }
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.ObjectIdentifier, GetBody());
 }
Exemplo n.º 32
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.NumericString, GetOctets());
 }
Exemplo n.º 33
0
        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());
        }
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.GraphicString, mString);
 }
Exemplo n.º 35
0
		internal override void Encode(DerOutputStream derOut)
		{
			MemoryStream ms = new MemoryStream();
			WriteEncodable(ms, directReference);
			WriteEncodable(ms, indirectReference);
			WriteEncodable(ms, dataValueDescriptor);
			WriteEncodable(ms, new DerTaggedObject(Asn1Tags.External, externalContent));

			derOut.WriteEncoded(Asn1Tags.Constructed, Asn1Tags.External, ms.ToArray());
		}
Exemplo n.º 36
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 Set,
         * 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
            using (var bOut = new MemoryStream())
            {
                using (var dOut = new DerOutputStream(bOut))
                {
                    foreach (Asn1Encodable obj in this)
                    {
                        dOut.WriteObject(obj);
                    }
                }

                var bytes = bOut.ToArray();

                derOut.WriteEncoded(Asn1Tags.Set | Asn1Tags.Constructed, bytes);
            }
        }
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.GeneralString, this.GetOctets());
 }
Exemplo n.º 38
0
		internal override void Encode(
            DerOutputStream derOut)
        {
            char[] c = str.ToCharArray();
            byte[] b = new byte[c.Length * 2];

			for (int i = 0; i != c.Length; i++)
            {
                b[2 * i] = (byte)(c[i] >> 8);
                b[2 * i + 1] = (byte)c[i];
            }

            derOut.WriteEncoded(Asn1Tags.BmpString, b);
        }
Exemplo n.º 39
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(25, mString);
 }
Exemplo n.º 40
0
        internal override void Encode(
            DerOutputStream derOut)
        {
			derOut.WriteEncoded(isConstructed ? Asn1Tags.Constructed : 0, tag, data);
        }
Exemplo n.º 41
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(6, GetBody());
 }
Exemplo n.º 42
0
		internal override void Encode(
			DerOutputStream derOut)
        {
            derOut.WriteEncoded(Asn1Tags.Utf8String, Encoding.UTF8.GetBytes(str));
        }
Exemplo n.º 43
0
		internal override void Encode(
            DerOutputStream derOut)
        {
			// TODO Should we make sure the byte value is one of '0' or '0xff' here?
			derOut.WriteEncoded(Asn1Tags.Boolean, new byte[]{ value });
        }
Exemplo n.º 44
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(5, zeroBytes);
 }
Exemplo n.º 45
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.VideotexString, mString);
 }
Exemplo n.º 46
0
 internal override void Encode(DerOutputStream derOut)
 {
     byte[] bytes = new byte[] { this.value };
     derOut.WriteEncoded(1, bytes);
 }
Exemplo n.º 47
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.GeneralizedTime, GetOctets());
 }
Exemplo n.º 48
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     // TODO Should we make sure the byte value is one of '0' or '0xff' here?
     derOut.WriteEncoded(Asn1Tags.Boolean, new byte[] { value });
 }
Exemplo n.º 49
0
		internal override void Encode(
			DerOutputStream  derOut)
		{
			derOut.WriteEncoded(Asn1Tags.Null, zeroBytes);
		}
		internal override void Encode(
			DerOutputStream derOut)
        {
			int classBits = Asn1Tags.Application;
			if (isConstructed)
			{
				classBits |= Asn1Tags.Constructed; 
			}

			derOut.WriteEncoded(classBits, tag, octets);
		}
Exemplo n.º 51
0
 internal override void Encode(DerOutputStream derOut)
 {
     derOut.WriteEncoded(27, this.GetOctets());
 }
Exemplo n.º 52
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(Asn1Tags.T61String, GetOctets());
 }
Exemplo n.º 53
0
 internal override void Encode(
     DerOutputStream derOut)
 {
     derOut.WriteEncoded(tag, data);
 }