return writer.toByteArray();
}
public static HandshakeMessage fromByteArray(byte[] byteArray) {
DatagramReader reader = new DatagramReader(byteArray);
int length = reader.read(CERTIFICATE_TYPES_LENGTH_BITS);
List<ClientCertificateType> certificateTypes = new ArrayList<ClientCertificateType>();
for (int i = 0; i < length; i++) {
int code = reader.read(CERTIFICATE_TYPE_BITS);
certificateTypes.add(ClientCertificateType.getTypeByCode(code));
}
length = reader.read(SUPPORTED_SIGNATURE_LENGTH_BITS);
List<SignatureAndHashAlgorithm> supportedSignatureAlgorithms = new ArrayList<SignatureAndHashAlgorithm>();
for (int i = 0; i < length; i += 2) {
int codeHash = reader.read(SUPPORTED_SIGNATURE_BITS);
int codeSignature = reader.read(SUPPORTED_SIGNATURE_BITS);
supportedSignatureAlgorithms.add(new SignatureAndHashAlgorithm(HashAlgorithm.getAlgorithmByCode(codeHash), SignatureAlgorithm.getAlgorithmByCode(codeSignature)));
}
length = reader.read(CERTIFICATE_AUTHORITIES_LENGTH_BITS);
List<DistinguishedName> certificateAuthorities = new ArrayList<DistinguishedName>();
while (length > 0) {
int nameLength = reader.read(CERTIFICATE_AUTHORITY_LENGTH_BITS);
byte[] name = reader.readBytes(nameLength);
certificateAuthorities.add(new DistinguishedName(name));
length -= 2 + name.length;
}