Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim key #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static KeyWithType fromString(String keyWithType) {
checkArgument(keyWithType.contains(":"), "Key must be in the format <type>:<key in base64>");

String[] tokens = keyWithType.split(":", 2);
byte[] decodedKey = BaseEncoding.base64().decode(tokens[1]);
byte[] decodedKey = BaseEncoding.base64().decode(tokens[1].trim());

// legacy RSA key format
if (tokens[0].equals("RSA")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,24 @@

public final class KeyWithTypeTest {
private static final ObjectMapper mapper = new ObjectMapper();
private static final String kwtString = "AES:rqrvWpLld+wKLOyxJYxQVg==";
private static final KeyWithType kwt = KeyWithType.fromString(kwtString);

@Test
public void testSerialization() throws IOException {
String kwtString = "AES:rqrvWpLld+wKLOyxJYxQVg==";
KeyWithType kwt = KeyWithType.fromString(kwtString);
String serialized = mapper.writeValueAsString(kwt);

String expectedSerialization = String.format("\"%s\"", kwtString);
assertThat(serialized, is(expectedSerialization));

KeyWithType deserialized = mapper.readValue(serialized, KeyWithType.class);
assertThat(deserialized.toString(), is(kwt.toString()));
}

@Test
public void testSerializationNewLine() throws IOException {
String kwtString = "AES:rqrvWpLld+wKLOyxJYxQVg==";
KeyWithType kwt = KeyWithType.fromString(kwtString + "\n");
String serialized = mapper.writeValueAsString(kwt);

String expectedSerialization = String.format("\"%s\"", kwtString);
Expand Down