Skip to content
Open
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 @@ -74,6 +74,11 @@ public static SchnorrKeyPair from(@NonNull final SchnorrKeys keys) {
return new SchnorrKeyPair(Bytes.wrap(keys.privateKey()), Bytes.wrap(keys.publicKey()));
}

@Override
public @NonNull String toString() {
return "SchnorrKeyPair[privateKey=<redacted>, publicKey=" + publicKey + "]";
}

/**
* Translates a byte array into a {@link SchnorrKeyPair} instance.
* @param bytes the byte array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public record SchnorrKeyPair(
requireNonNull(publicKey);
}

@Override
public @NonNull String toString() {
return "SchnorrKeyPair[privateKey=<redacted>, publicKey=" + publicKey + "]";
}

/**
* Translates a byte array into a {@link SchnorrKeyPair}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public record TssKeyPair(@NonNull Bytes privateKey, @NonNull Bytes publicKey) {
requireNonNull(privateKey);
requireNonNull(publicKey);
}

@Override
public @NonNull String toString() {
return "TssKeyPair[privateKey=<redacted>, publicKey=" + publicKey + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
package com.hedera.node.app.history.impl;

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

import com.hedera.pbj.runtime.io.buffer.Bytes;
import org.junit.jupiter.api.Test;

class ProofKeysAccessorImplTest {
@Test
void schnorrKeyPairToStringRedactsPrivateKey() {
final var privateKey = Bytes.wrap("private");
final var publicKey = Bytes.wrap("public");
final var keyPair = new ProofKeysAccessorImpl.SchnorrKeyPair(privateKey, publicKey);

final var asString = keyPair.toString();

assertEquals("SchnorrKeyPair[privateKey=<redacted>, publicKey=" + publicKey + "]", asString);
assertFalse(asString.contains(privateKey.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
Expand Down Expand Up @@ -67,6 +68,18 @@ void schnorrKeyPairRoundTripsThroughDelimitedBytes() {
assertArrayEquals(bytes, roundTripped.toDelimitedBytes());
}

@Test
void schnorrKeyPairToStringRedactsPrivateKey() {
final var privateKey = Bytes.wrap("private");
final var publicKey = Bytes.wrap("public");
final var keyPair = new TssKeyFiles.SchnorrKeyPair(privateKey, publicKey);

final var asString = keyPair.toString();

assertEquals("SchnorrKeyPair[privateKey=<redacted>, publicKey=" + publicKey + "]", asString);
assertFalse(asString.contains(privateKey.toString()));
}

@Test
void rejectsMalformedDelimitedSchnorrKeyPair() {
assertThrows(IllegalArgumentException.class, () -> TssKeyFiles.SchnorrKeyPair.fromDelimited(new byte[] {3, 1}));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
package com.hedera.node.app.tss;

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

import com.hedera.pbj.runtime.io.buffer.Bytes;
import org.junit.jupiter.api.Test;

class TssKeyPairTest {
@Test
void toStringRedactsPrivateKey() {
final var privateKey = Bytes.wrap("private");
final var publicKey = Bytes.wrap("public");
final var keyPair = new TssKeyPair(privateKey, publicKey);

final var asString = keyPair.toString();

assertEquals("TssKeyPair[privateKey=<redacted>, publicKey=" + publicKey + "]", asString);
assertFalse(asString.contains(privateKey.toString()));
}
}
Loading