[java-support] 01/01: JSPT-100 - Add Base32 output format to StringDigester
Scott Cantor
cantor.2 at osu.edu
Thu Jun 4 16:06:31 UTC 2020
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch dev/JSPT-100
in repository java-support.
View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=2385c22d8dd1ea23d6e34ea539b94e9c87d3206f
commit 2385c22d8dd1ea23d6e34ea539b94e9c87d3206f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jun 4 12:06:18 2020 -0400
JSPT-100 - Add Base32 output format to StringDigester
https://issues.shibboleth.net/jira/browse/JSPT-100
---
.../java/support/codec/StringDigester.java | 37 ++++++++++++++--------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/codec/StringDigester.java b/src/main/java/net/shibboleth/utilities/java/support/codec/StringDigester.java
index 9d6394d..b744dc4 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/codec/StringDigester.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/codec/StringDigester.java
@@ -36,8 +36,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * A function impl which accepts a String input, digests it according to a specified {@link MessageDigest} algorithm,
- * and then returns the output in a specified format: Base64-encoded or hexadecimal with with lower or upper
+ * A function which accepts a String input, digests it according to a specified {@link MessageDigest} algorithm,
+ * and then returns the output in a specified format: Base32/64-encoded or hexadecimal with with lower or upper
* case characters.
*/
public class StringDigester implements Function<String,String> {
@@ -49,7 +49,9 @@ public class StringDigester implements Function<String,String> {
/** Hexadecimal encoding, with lower case characters.*/
HEX_LOWER,
/** Hexadecimal encoding, with upper case characters.*/
- HEX_UPPER
+ HEX_UPPER,
+ /** Base32-encoding. */
+ BASE32
};
/** The default input character set.*/
@@ -174,31 +176,40 @@ public class StringDigester implements Function<String,String> {
return null;
}
- String output = null;
+ final String output = encodeOutput(digestedBytes);
+ log.debug("Produced digested and formatted output '{}'", output);
+ return output;
+ }
+
+ @Nullable private String encodeOutput(@Nonnull final byte[] digestedBytes) {
switch(outputFormat) {
+ case BASE32:
+ try {
+ return Base32Support.encode(digestedBytes, false);
+ } catch (final EncodingException e) {
+ //unlikely to happen.
+ log.warn("Could not base32 encode digest bytes, no data returned",e);
+ return null;
+ }
case BASE64:
try {
- output = Base64Support.encode(digestedBytes, false);
+ return Base64Support.encode(digestedBytes, false);
} catch (final EncodingException e) {
//unlikely to happen.
log.warn("Could not base64 encode digest bytes, no data returned",e);
return null;
}
- break;
case HEX_LOWER:
- output = new String(Hex.encodeHex(digestedBytes, true));
- break;
+ return new String(Hex.encodeHex(digestedBytes, true));
case HEX_UPPER:
- output = new String(Hex.encodeHex(digestedBytes, false));
- break;
+ return new String(Hex.encodeHex(digestedBytes, false));
default:
break;
}
- log.debug("Produced digested and formatted output '{}'", output);
-
- return output;
+ log.error("Unsupported output format");
+ return null;
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list