Ejemplo n.º 1
0
    public virtual void Encode(Stream output)
    {
        if (mCertificateTypes == null || mCertificateTypes.Length == 0)
        {
            TlsUtilities.WriteUint8(0, output);
        }
        else
        {
            TlsUtilities.WriteUint8ArrayWithUint8Length(mCertificateTypes, output);
        }
        if (mSupportedSignatureAlgorithms != null)
        {
            TlsUtilities.EncodeSupportedSignatureAlgorithms(mSupportedSignatureAlgorithms, allowAnonymous: false, output);
        }
        if (mCertificateAuthorities == null || mCertificateAuthorities.Count < 1)
        {
            TlsUtilities.WriteUint16(0, output);
            return;
        }
        IList list = Platform.CreateArrayList(mCertificateAuthorities.Count);
        int   num  = 0;

        foreach (Asn1Encodable mCertificateAuthority in mCertificateAuthorities)
        {
            byte[] encoded = mCertificateAuthority.GetEncoded("DER");
            list.Add(encoded);
            num += encoded.Length + 2;
        }
        TlsUtilities.CheckUint16(num);
        TlsUtilities.WriteUint16(num, output);
        foreach (byte[] item in list)
        {
            TlsUtilities.WriteOpaque16(item, output);
        }
    }
Ejemplo n.º 2
0
        /**
         * Encode this {@link CertificateRequest} to a {@link Stream}.
         *
         * @param output the {@link Stream} to encode to.
         * @throws IOException
         */
        public virtual void Encode(Stream output)
        {
            if (mCertificateTypes == null || mCertificateTypes.Length == 0)
            {
                TlsUtilities.WriteUint8(0, output);
            }
            else
            {
                TlsUtilities.WriteUint8ArrayWithUint8Length(mCertificateTypes, output);
            }

            if (mSupportedSignatureAlgorithms != null)
            {
                // TODO Check whether SignatureAlgorithm.anonymous is allowed here
                TlsUtilities.EncodeSupportedSignatureAlgorithms(mSupportedSignatureAlgorithms, false, output);
            }

            if (mCertificateAuthorities == null || mCertificateAuthorities.Count < 1)
            {
                TlsUtilities.WriteUint16(0, output);
            }
            else
            {
                IList derEncodings = Platform.CreateArrayList(mCertificateAuthorities.Count);

                int totalLength = 0;
                foreach (Asn1Encodable certificateAuthority in mCertificateAuthorities)
                {
                    byte[] derEncoding = certificateAuthority.GetEncoded(Asn1Encodable.Der);
                    derEncodings.Add(derEncoding);
                    totalLength += derEncoding.Length + 2;
                }

                TlsUtilities.CheckUint16(totalLength);
                TlsUtilities.WriteUint16(totalLength, output);

                foreach (byte[] derEncoding in derEncodings)
                {
                    TlsUtilities.WriteOpaque16(derEncoding, output);
                }
            }
        }