-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Noop encryption should encode to base64
- Loading branch information
1 parent
e10d67d
commit d600f12
Showing
3 changed files
with
27 additions
and
12 deletions.
There are no files selected for viewing
14 changes: 11 additions & 3 deletions
14
src/main/java/io/github/rabobank/shadow_tool/NoopEncryptionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
package io.github.rabobank.shadow_tool; | ||
|
||
import org.bouncycastle.util.encoders.Base64; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
/** | ||
* A version of the Encryption Service that doesn't perform any encryption. | ||
* A version of the Encryption Service that doesn't perform any encryption, | ||
* it only encodes the differences as a Base 64 String. | ||
* <p> | ||
* This might be useful for simple use-case where encryption of differences is not required, | ||
* for example with public data. | ||
* | ||
* @see Base64#toBase64String(byte[]) | ||
*/ | ||
class NoopEncryptionService implements EncryptionService { | ||
public class NoopEncryptionService implements EncryptionService { | ||
public static final NoopEncryptionService INSTANCE = new NoopEncryptionService(); | ||
|
||
NoopEncryptionService() { | ||
} | ||
|
||
@Override | ||
public String encrypt(final String value) { | ||
return value; | ||
return Base64.toBase64String(value.getBytes(UTF_8)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
src/test/java/io/github/rabobank/shadow_tool/NoopEncryptionServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
package io.github.rabobank.shadow_tool; | ||
|
||
import org.bouncycastle.util.encoders.Base64; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class NoopEncryptionServiceTest { | ||
@Test | ||
void valuesAreNotEncrypted() { | ||
void encryptAndDecrypt() { | ||
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); | ||
//Decrypt and verify | ||
final var decoded = Base64.decode(encryptedDifferences); | ||
final var result = new String(decoded, UTF_8); | ||
|
||
assertEquals(plainDifferences, encryptedDifferences); | ||
assertEquals(plainDifferences, result); | ||
} | ||
} |