Unit tests for KeyAgreementTransport.

This commit is contained in:
akwizgran
2016-12-21 14:08:21 +00:00
parent 79fc41477c
commit 2390f767f5
2 changed files with 263 additions and 16 deletions

View File

@@ -98,28 +98,24 @@ class KeyAgreementTransport {
private byte[] readRecord(byte expectedType) throws AbortException {
while (true) {
byte[] header = readHeader();
byte version = header[0], type = header[1];
int len = ByteUtils.readUint16(header,
RECORD_HEADER_PAYLOAD_LENGTH_OFFSET);
if (header[0] != PROTOCOL_VERSION) {
throw new AbortException(false);
}
byte type = header[1];
// Reject unrecognised protocol version
if (version != PROTOCOL_VERSION) throw new AbortException(false);
if (type == ABORT) throw new AbortException(true);
if (type != expectedType) {
if (type != KEY && type != CONFIRM) {
// ignore unrecognised record and try next
try {
readData(len);
} catch (IOException e) {
throw new AbortException(e);
}
continue;
} else {
throw new AbortException(false);
if (type == expectedType) {
try {
return readData(len);
} catch (IOException e) {
throw new AbortException(e);
}
}
// Reject recognised but unexpected record type
if (type == KEY || type == CONFIRM) throw new AbortException(false);
// Skip unrecognised record type
try {
return readData(len);
readData(len);
} catch (IOException e) {
throw new AbortException(e);
}