Skip to content

Commit

Permalink
Cleanup OHttpCrypto to only expose types that are really required
Browse files Browse the repository at this point in the history
Motivation:

Let's only expose types in abstract methods that are really required.

Modifications:

Let's only expose what is needed.

Result:

Cleanup
  • Loading branch information
normanmaurer committed Dec 27, 2023
1 parent 42bbd9b commit dbf8bb1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static ByteBuf aad(boolean isFinal) {

protected abstract CryptoDecryptContext decryptCrypto();

protected abstract OHttpCryptoConfiguration configuration();
protected abstract boolean useFinalAad();

/**
* Encrypt a message of a given length and write the encrypted data to a buffer.
Expand All @@ -55,7 +55,7 @@ private static ByteBuf aad(boolean isFinal) {
* @throws CryptoException thrown when an error happens.
*/
public final void encrypt(ByteBuf message, int messageLength, boolean isFinal, ByteBuf out) throws CryptoException {
encryptCrypto().seal(aad(isFinal && configuration().useFinalAad()),
encryptCrypto().seal(aad(isFinal && useFinalAad()),
message.slice(message.readerIndex(), messageLength), out);
message.skipBytes(messageLength);
}
Expand All @@ -71,7 +71,7 @@ public final void encrypt(ByteBuf message, int messageLength, boolean isFinal, B
*/
public final void decrypt(ByteBuf message, int messageLength, boolean isFinal, ByteBuf out) throws CryptoException {
decryptCrypto().open(
aad(isFinal && configuration().useFinalAad()),
aad(isFinal && useFinalAad()),
message.slice(message.readerIndex(), messageLength), out);
message.skipBytes(messageLength);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ public void writeResponseNonce(ByteBuf out) {

@Override
protected CryptoEncryptContext encryptCrypto() {
return this.aead;
return aead;
}

@Override
protected CryptoDecryptContext decryptCrypto() {
return this.context;
return context;
}

@Override
protected OHttpCryptoConfiguration configuration() {
return configuration;
protected boolean useFinalAad() {
return configuration.useFinalAad();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected CryptoDecryptContext decryptCrypto() {
}

@Override
protected OHttpCryptoConfiguration configuration() {
return configuration;
protected boolean useFinalAad() {
return configuration.useFinalAad();
}
}

0 comments on commit dbf8bb1

Please sign in to comment.