Skip to content

Commit

Permalink
[JENKINS-16301] Replace impl of getDigestOf with standard (Commons Co…
Browse files Browse the repository at this point in the history
…dec) DigestUtils.md5Hex, for simplicity.
  • Loading branch information
jglick committed May 21, 2013
1 parent b5d96e2 commit 51fbd2d
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -30,11 +30,9 @@
import hudson.Proc.LocalProc;
import hudson.model.TaskListener;
import hudson.os.PosixAPI;
import hudson.util.IOException2;
import hudson.util.QuotedStringTokenizer;
import hudson.util.VariableResolver;
import hudson.util.jna.WinIOException;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.tools.ant.BuildException;
Expand All @@ -45,7 +43,6 @@
import org.jruby.ext.posix.FileStat;
import org.jruby.ext.posix.POSIX;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import org.kohsuke.stapler.Stapler;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
Expand All @@ -61,7 +58,6 @@
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.NumberFormat;
Expand All @@ -76,6 +72,7 @@
import hudson.util.jna.Kernel32Utils;

import static hudson.util.jna.GNUCLibrary.LIBC;
import org.apache.commons.codec.digest.DigestUtils;

/**
* Various utility methods that don't have more proper home.
Expand Down Expand Up @@ -554,23 +551,10 @@ public static String ensureEndsWith(String subject, String suffix) {
* The stream will be closed by this method at the end of this method.
* @return
* 32-char wide string
* @see DigestUtils#md5(InputStream)
*/
public static String getDigestOf(InputStream source) throws IOException {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");

byte[] buffer = new byte[1024];
DigestInputStream in =new DigestInputStream(source,md5);
try {
while(in.read(buffer)>=0)
; // simply discard the input
} finally {
in.close();
}
return toHexString(md5.digest());
} catch (NoSuchAlgorithmException e) {
throw new IOException2("MD5 not installed",e); // impossible
}
return DigestUtils.md5Hex(source);
}

public static String getDigestOf(String text) {
Expand Down

2 comments on commit 51fbd2d

@jglick
Copy link
Member Author

@jglick jglick commented on 51fbd2d Jun 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected in 7f966f6.

@jglick
Copy link
Member Author

@jglick jglick commented on 51fbd2d Jul 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.