[java-metadata-aggregator] branch main updated: MDA-269 - Remove dependencies on the default Charset
Ian Young
ian at iay.org.uk
Tue Oct 18 15:29:58 UTC 2022
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch main
in repository java-metadata-aggregator.
View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=6a1ad60ab3bc542f4444c5cd66e015ae1a3b280d
The following commit(s) were added to refs/heads/main by this push:
new 6a1ad60 MDA-269 - Remove dependencies on the default Charset
6a1ad60 is described below
commit 6a1ad60ab3bc542f4444c5cd66e015ae1a3b280d
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Tue Oct 18 16:29:54 2022 +0100
MDA-269 - Remove dependencies on the default Charset
https://shibboleth.atlassian.net/browse/MDA-269
---
.../metadata/pipeline/MDQueryMD5ItemIdTransformer.java | 10 ++++++----
.../metadata/pipeline/MDQuerySHA1ItemIdTransformer.java | 9 +++++----
.../net/shibboleth/metadata/util/SHA1StringTransformer.java | 8 ++++----
.../validate/x509/X509RSAOpenSSLBlacklistValidator.java | 3 ++-
.../MDQueryMD5ItemIdTransformerTest.java} | 12 ++++++++----
.../MDQuerySHA1ItemIdTransformerTest.java} | 12 ++++++++----
.../shibboleth/metadata/util/SHA1StringTransformerTest.java | 4 ++++
7 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQueryMD5ItemIdTransformer.java b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQueryMD5ItemIdTransformer.java
index aafdefe..49e38f2 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQueryMD5ItemIdTransformer.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQueryMD5ItemIdTransformer.java
@@ -17,9 +17,9 @@
package net.shibboleth.metadata.pipeline;
+import java.nio.charset.StandardCharsets;
import java.util.function.Function;
-import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
import org.bouncycastle.crypto.digests.MD5Digest;
@@ -27,7 +27,8 @@ import org.cryptacular.util.CodecUtil;
import org.cryptacular.util.HashUtil;
/**
- * Transforms a string into another string that is the MD5 hash of the original string prepended with "{md5}".
+ * Transforms a string into another string that is the MD5 hash of the UTF-8 encoding
+ * of the original string, prepended with "{md5}".
*
* @since 0.9.0
*/
@@ -35,7 +36,8 @@ import org.cryptacular.util.HashUtil;
public class MDQueryMD5ItemIdTransformer implements Function<String, String> {
@Override
- public String apply(@Nonnull final String source) {
- return "{md5}" + CodecUtil.hex(HashUtil.hash(new MD5Digest(), source.getBytes()));
+ public String apply(final String source) {
+ return "{md5}" + CodecUtil.hex(HashUtil.hash(new MD5Digest(),
+ source.getBytes(StandardCharsets.UTF_8)));
}
}
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQuerySHA1ItemIdTransformer.java b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQuerySHA1ItemIdTransformer.java
index 37ae596..d53cbc8 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQuerySHA1ItemIdTransformer.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/MDQuerySHA1ItemIdTransformer.java
@@ -17,16 +17,17 @@
package net.shibboleth.metadata.pipeline;
+import java.nio.charset.StandardCharsets;
import java.util.function.Function;
-import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
import org.cryptacular.util.CodecUtil;
import org.cryptacular.util.HashUtil;
/**
- * Transforms a string into another string that is the SHA1 hash of the original string prepended with "{sha1}".
+ * Transforms a string into another string that is the hex-encoded representation of the
+ * SHA1 hash of the UTF-8 encoding of the original string, prepended with "{sha1}".
*
* @since 0.9.0
*/
@@ -34,7 +35,7 @@ import org.cryptacular.util.HashUtil;
public class MDQuerySHA1ItemIdTransformer implements Function<String, String> {
@Override
- public String apply(@Nonnull final String source) {
- return "{sha1}" + CodecUtil.hex(HashUtil.sha1(source.getBytes()));
+ public String apply(final String source) {
+ return "{sha1}" + CodecUtil.hex(HashUtil.sha1(source.getBytes(StandardCharsets.UTF_8)));
}
}
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/util/SHA1StringTransformer.java b/mda-framework/src/main/java/net/shibboleth/metadata/util/SHA1StringTransformer.java
index 37befed..bf404ca 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/util/SHA1StringTransformer.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/util/SHA1StringTransformer.java
@@ -17,9 +17,9 @@
package net.shibboleth.metadata.util;
+import java.nio.charset.StandardCharsets;
import java.util.function.Function;
-import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import org.cryptacular.util.CodecUtil;
@@ -27,7 +27,7 @@ import org.cryptacular.util.HashUtil;
/**
* A {@link Function} that transforms a {@link String} into a hex-encoded representation of
- * the SHA-1 digest of the string.
+ * the SHA-1 digest of the UTF-8 encoding of the string.
*
* @since 0.9.2
*/
@@ -35,8 +35,8 @@ import org.cryptacular.util.HashUtil;
public class SHA1StringTransformer implements Function<String, String> {
@Override
- public String apply(@Nonnull final String input) {
- return CodecUtil.hex(HashUtil.sha1(input.getBytes()));
+ public String apply(final String input) {
+ return CodecUtil.hex(HashUtil.sha1(input.getBytes(StandardCharsets.UTF_8)));
}
}
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/validate/x509/X509RSAOpenSSLBlacklistValidator.java b/mda-framework/src/main/java/net/shibboleth/metadata/validate/x509/X509RSAOpenSSLBlacklistValidator.java
index 2144e18..d5da27c 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/validate/x509/X509RSAOpenSSLBlacklistValidator.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/validate/x509/X509RSAOpenSSLBlacklistValidator.java
@@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
@@ -202,7 +203,7 @@ public class X509RSAOpenSSLBlacklistValidator extends AbstractX509Validator {
}
try (BufferedReader reader =
- new BufferedReader(new InputStreamReader(blacklistResource.getInputStream()))) {
+ new BufferedReader(new InputStreamReader(blacklistResource.getInputStream(), StandardCharsets.UTF_8))) {
while (true) {
final String line = reader.readLine();
if (line == null) {
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/MDQueryMD5ItemIdTransformerTest.java
similarity index 75%
copy from mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java
copy to mda-framework/src/test/java/net/shibboleth/metadata/pipeline/MDQueryMD5ItemIdTransformerTest.java
index f96322c..28481ec 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/MDQueryMD5ItemIdTransformerTest.java
@@ -16,21 +16,25 @@
*/
-package net.shibboleth.metadata.util;
+package net.shibboleth.metadata.pipeline;
import java.util.function.Function;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class SHA1StringTransformerTest {
+public class MDQueryMD5ItemIdTransformerTest {
private static final Function<String, String> transform =
- new SHA1StringTransformer();
+ new MDQueryMD5ItemIdTransformer();
@Test public void testMDQExample() {
Assert.assertEquals(transform.apply("http://example.org/service"),
- "11d72e8cf351eb6c75c721e838f469677ab41bdb");
+ "{md5}f3678248a29ab8e8e5b1b00bee4060e0");
}
+ @Test public void testUTF8Example() {
+ Assert.assertEquals(transform.apply("Cherry \u03c0"), // pi
+ "{md5}37b47884fe3429710db40d81de044a7d");
+ }
}
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/MDQuerySHA1ItemIdTransformerTest.java
similarity index 74%
copy from mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java
copy to mda-framework/src/test/java/net/shibboleth/metadata/pipeline/MDQuerySHA1ItemIdTransformerTest.java
index f96322c..62d1e70 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/MDQuerySHA1ItemIdTransformerTest.java
@@ -16,21 +16,25 @@
*/
-package net.shibboleth.metadata.util;
+package net.shibboleth.metadata.pipeline;
import java.util.function.Function;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class SHA1StringTransformerTest {
+public class MDQuerySHA1ItemIdTransformerTest {
private static final Function<String, String> transform =
- new SHA1StringTransformer();
+ new MDQuerySHA1ItemIdTransformer();
@Test public void testMDQExample() {
Assert.assertEquals(transform.apply("http://example.org/service"),
- "11d72e8cf351eb6c75c721e838f469677ab41bdb");
+ "{sha1}11d72e8cf351eb6c75c721e838f469677ab41bdb");
}
+ @Test public void testUTF8Example() {
+ Assert.assertEquals(transform.apply("Cherry \u03c0"), // pi
+ "{sha1}2b159a35a20c66bfc91e3d7516db5d94ec6d2776");
+ }
}
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java
index f96322c..17fe5cd 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/util/SHA1StringTransformerTest.java
@@ -33,4 +33,8 @@ public class SHA1StringTransformerTest {
"11d72e8cf351eb6c75c721e838f469677ab41bdb");
}
+ @Test public void testUTF8Example() {
+ Assert.assertEquals(transform.apply("Cherry \u03c0"), // pi
+ "2b159a35a20c66bfc91e3d7516db5d94ec6d2776");
+ }
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list