Skip to content
This repository was archived by the owner on Mar 15, 2021. It is now read-only.

Commit 0b74c74

Browse files
committed
Ensure every value has a hash
1 parent 84b339c commit 0b74c74

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎src/main/java/uk/gov/objecthash/StringValue.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
import org.apache.commons.codec.DecoderException;
44
import org.apache.commons.codec.binary.Hex;
5-
import uk.gov.objecthash.exceptions.InvalidRedactedValue;
6-
7-
import java.io.UnsupportedEncodingException;
8-
import java.nio.charset.StandardCharsets;
95

106
public class StringValue implements ObjectHashable {
117
private final String value;
@@ -20,7 +16,13 @@ public byte[] digest() {
2016
try {
2117
return Hex.decodeHex(hexDigest);
2218
} catch (DecoderException e) {
23-
throw new InvalidRedactedValue("Invalid hex digest: " + hexDigest, e);
19+
/*
20+
* If the redacted value is not valid hex, then treat it as
21+
* a non-redacted string. This ensures that every possible
22+
* data structure has a hash. We do not enforce that the hash
23+
* length matches any particular hashing algorithm, only that
24+
* it is hex encoded.
25+
*/
2426
}
2527
}
2628

‎src/main/java/uk/gov/objecthash/exceptions/InvalidRedactedValue.java‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎src/test/java/uk/gov/objecthash/ObjectHashTest.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,10 @@ public void returnsSuppliedHashIfRedacted() {
148148
public void hashesKnownRedactedHash() {
149149
assertEquals(ObjectHash.toHexDigest("**REDACTED**2a42a9c91b74c0032f6b8000a2c9c5bcca5bb298f004e8eff533811004dea511"), "2a42a9c91b74c0032f6b8000a2c9c5bcca5bb298f004e8eff533811004dea511" );
150150
}
151+
152+
@Test
153+
public void hashesInvalidRedactedValues() {
154+
assertEquals(ObjectHash.toHexDigest("**REDACTED**banana"), "525b975c2979f427dcb79db8992035a9c2157a3c54492050753b9af552756c7a");
155+
}
151156

152157
}

0 commit comments

Comments
 (0)