summaryrefslogtreecommitdiffstats
path: root/security-utils/src/main/java/com/yahoo/security/SealedSharedKey.java
diff options
context:
space:
mode:
Diffstat (limited to 'security-utils/src/main/java/com/yahoo/security/SealedSharedKey.java')
-rw-r--r--security-utils/src/main/java/com/yahoo/security/SealedSharedKey.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/security-utils/src/main/java/com/yahoo/security/SealedSharedKey.java b/security-utils/src/main/java/com/yahoo/security/SealedSharedKey.java
index 99d07465812..20745ab4312 100644
--- a/security-utils/src/main/java/com/yahoo/security/SealedSharedKey.java
+++ b/security-utils/src/main/java/com/yahoo/security/SealedSharedKey.java
@@ -2,6 +2,10 @@
package com.yahoo.security;
import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Objects;
+
+import static com.yahoo.security.ArrayUtils.hex;
/**
* A SealedSharedKey represents the public part of a secure one-way ephemeral key exchange.
@@ -97,4 +101,35 @@ public record SealedSharedKey(int version, KeyId keyId, byte[] enc, byte[] ciphe
}
}
+ // Friendlier toString() with hex dump of enc/ciphertext fields
+ @Override
+ public String toString() {
+ return "SealedSharedKey{" +
+ "version=" + version +
+ ", keyId=" + keyId +
+ ", enc=" + hex(enc) +
+ ", ciphertext=" + hex(ciphertext) +
+ '}';
+ }
+
+ // Explicitly generated equals() and hashCode() to use _contents_ of
+ // enc/ciphertext arrays, and not just their refs.
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ SealedSharedKey that = (SealedSharedKey) o;
+ return version == that.version && keyId.equals(that.keyId) &&
+ Arrays.equals(enc, that.enc) &&
+ Arrays.equals(ciphertext, that.ciphertext);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = Objects.hash(version, keyId);
+ result = 31 * result + Arrays.hashCode(enc);
+ result = 31 * result + Arrays.hashCode(ciphertext);
+ return result;
+ }
+
}