[java-support] branch master updated: Enhance StringDigester to avoid returning unsalted data.

Scott Cantor cantor.2 at osu.edu
Thu Nov 5 15:24:10 EST 2015


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch master
in repository java-support.

The following commit(s) were added to refs/heads/master by this push:
       new  ed51e27   Enhance StringDigester to avoid returning unsalted data.
ed51e27 is described below

commit ed51e27ebb81fc8ed5aa2bb0078f01c728a61cfa
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Nov 5 15:24:22 2015 -0500

    Enhance StringDigester to avoid returning unsalted data.
---
 .../java/support/codec/StringDigester.java         | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 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 7145777..27f56c7 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
@@ -70,6 +70,9 @@ public class StringDigester implements Function<String, String> {
     /** Optional salt to add into the digest. */
     @Nullable private String salt;
     
+    /** Whether to require a salt to return any output. */
+    private boolean requireSalt;
+    
     /**
      * Constructor.
      * 
@@ -108,6 +111,7 @@ public class StringDigester implements Function<String, String> {
             inputCharset = DEFAULT_INPUT_CHARSET;
         }
         
+        requireSalt = false;
     }
     
     /**
@@ -115,8 +119,21 @@ public class StringDigester implements Function<String, String> {
      * 
      * @param s salt value
      */
-    public void setSalt(@Nullable final String s) {
-        salt = s;
+    public void setSalt(@Nullable @NotEmpty final String s) {
+        if (s != null && !s.isEmpty()) {
+            salt = s;
+        } else {
+            salt = null;
+        }
+    }
+    
+    /**
+     * Set whether to return any data if no salt is set.
+     * 
+     * @param flag  flag to set
+     */
+    public void setRequireSalt(final boolean flag) {
+        requireSalt = flag;
     }
 
     /** {@inheritDoc} */
@@ -129,6 +146,9 @@ public class StringDigester implements Function<String, String> {
         
         if (salt != null) {
             trimmed = salt + trimmed;
+        } else if (requireSalt) {
+            log.debug("Salt was required but missing, no data returned");
+            return null;
         }
         
         log.debug("Digesting input '{}' as charset '{}' with digest algorithm '{}' and output format '{}'", 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list