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

Only print base64 string value for a key if public. #1092

Merged
merged 1 commit into from
Jun 24, 2020
Merged
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 @@ -33,16 +33,16 @@ public final int hashCode() {
}

@Override
public final String toString() {
public String toString() {

final String typeName = Stream.of(getClass())
.map(Class::getInterfaces)
.flatMap(Stream::of)
.map(Class::getSimpleName)
.map(Class::getName)
.findFirst()
.get();

return String.format("%s[%s]", typeName, encodeToBase64());
return typeName + "@" + Integer.toHexString(hashCode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
package com.quorum.tessera.encryption;


import java.util.stream.Stream;

class PublicKeyImpl extends BaseKey implements PublicKey {

PublicKeyImpl(byte[] keyBytes) {
super(keyBytes);
}


@Override
public final String toString() {

final String typeName = Stream.of(getClass())
.map(Class::getInterfaces)
.flatMap(Stream::of)
.map(Class::getSimpleName)
.findFirst()
.get();

return String.format("%s[%s]", typeName, encodeToBase64());
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.quorum.tessera.encryption;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Parameterized.class)
public class KeyTest {
Expand All @@ -34,7 +36,15 @@ public void doTests() throws Exception {

assertThat(key.encodeToBase64()).isEqualTo(base64Value);

assertThat(key.toString()).isEqualTo(type.getSimpleName() + "[" + base64Value + "]");
if(this.type == PublicKey.class) {
assertThat(key.toString())
.isEqualTo("PublicKey[" + base64Value + "]");
} else {
assertThat(key.toString())
.isNotNull()
.doesNotContain(base64Value)
.contains(type.getSimpleName());
}

assertThat(key.hashCode()).isEqualTo(Arrays.hashCode(data));

Expand All @@ -50,7 +60,7 @@ public void doTests() throws Exception {
assertThat(key).isEqualTo(otherKeyWithSameData);
}

@Parameterized.Parameters
@Parameterized.Parameters(name = "{0}")
public static List<Class<? extends Key>> cases() {
return Arrays.asList(MasterKey.class, SharedKey.class, PrivateKey.class, PublicKey.class);
}
Expand Down