// Serialization //////////////////////////////////////////////////
@Override
public byte[] fragmentToByteArray() {
DatagramWriter writer = new DatagramWriter();
writer.write(certificateTypes.size(), CERTIFICATE_TYPES_LENGTH_BITS);
for (ClientCertificateType certificateType : certificateTypes) {
writer.write(certificateType.getCode(), CERTIFICATE_TYPE_BITS);
}
writer.write(supportedSignatureAlgorithms.size() * 2, SUPPORTED_SIGNATURE_LENGTH_BITS);
for (SignatureAndHashAlgorithm signatureAndHashAlgorithm : supportedSignatureAlgorithms) {
writer.write(signatureAndHashAlgorithm.getHash().getCode(), SUPPORTED_SIGNATURE_BITS);
writer.write(signatureAndHashAlgorithm.getSignature().getCode(), SUPPORTED_SIGNATURE_BITS);
}
writer.write(getCertificateAuthoritiesLength(), CERTIFICATE_AUTHORITIES_LENGTH_BITS);
for (DistinguishedName distinguishedName : certificateAuthorities) {
// since a distinguished name has variable length, we need to write length field for each name as well, has influence on total length!
writer.write(distinguishedName.getName().length, CERTIFICATE_AUTHORITY_LENGTH_BITS);
writer.writeBytes(distinguishedName.getName());
}
return writer.toByteArray();
}