Skip to content

Commit

Permalink
Add NoopEncryptionService
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvisser committed Nov 15, 2023
1 parent 56c78c3 commit e10d67d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.rabobank.shadow_tool;

/**
* A version of the Encryption Service that doesn't perform any encryption.
* This might be useful for simple use-case where encryption of differences is not required,
* for example with public data.
*/
class NoopEncryptionService implements EncryptionService {
public static final NoopEncryptionService INSTANCE = new NoopEncryptionService();

NoopEncryptionService() {
}

@Override
public String encrypt(final String value) {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void encryptAndDecrypt() throws Exception {
final var cipherText = decryptCipher.doFinal(Base64.decode(encryptedDifferences));
final var expectedUnencryptedResult = new String(cipherText, StandardCharsets.UTF_8);

assertEquals(expectedUnencryptedResult, plainDifferences);
assertEquals(plainDifferences, expectedUnencryptedResult);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.rabobank.shadow_tool;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class NoopEncryptionServiceTest {
@Test
void valuesAreNotEncrypted() {
final var encryptionService = NoopEncryptionService.INSTANCE;
final var plainDifferences = "'place' changed: 'Dintelooord' -> 'Dinteloord'\n" +
"'madrigals' collection changes :\n" +
" 1. 'Bruno' changed to 'Mirabel'\n" +
" 0. 'Bruno' added";
final var encryptedDifferences = encryptionService.encrypt(plainDifferences);

assertEquals(plainDifferences, encryptedDifferences);
}
}

0 comments on commit e10d67d

Please sign in to comment.