Skip to content

Commit e983a64

Browse files
author
Timothy O'Brien
committed
Removed the 1.4 method call on MessageDigest
from DigestUtils. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130216 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4cec5db commit e983a64

2 files changed

Lines changed: 7 additions & 54 deletions

File tree

src/java/org/apache/commons/codec/digest/DigestUtils.java

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959

6060
import java.security.MessageDigest;
6161
import java.security.NoSuchAlgorithmException;
62-
import java.security.Provider;
63-
import java.security.Security;
6462

6563
import org.apache.commons.codec.binary.Hex;
6664

@@ -72,13 +70,6 @@
7270
* @author David Graham
7371
*/
7472
public class DigestUtils {
75-
76-
/**
77-
* This is the provider which DigestUtils uses to get instances of the MD5 and SHA
78-
* algorithms. This variable is altered if a users wishes to customize the implementation
79-
* of an algorithm.
80-
*/
81-
private static Provider provider = null;
8273

8374
/**
8475
* Returns an MD5 MessageDigest.
@@ -87,13 +78,10 @@ public class DigestUtils {
8778
*/
8879
private static MessageDigest getMd5Digest() {
8980
try {
90-
if( provider != null ) {
91-
return MessageDigest.getInstance("MD5", provider);
92-
} else {
93-
return MessageDigest.getInstance("MD5");
94-
}
81+
return MessageDigest.getInstance("MD5");
82+
9583
} catch (NoSuchAlgorithmException e) {
96-
throw new RuntimeException("Unable to get instance of MD5 message digest in DigestUtils" + e.getMessage());
84+
throw new RuntimeException(e.getMessage());
9785
}
9886
}
9987

@@ -104,13 +92,10 @@ private static MessageDigest getMd5Digest() {
10492
*/
10593
private static MessageDigest getShaDigest() {
10694
try {
107-
if( provider != null) {
108-
return MessageDigest.getInstance("SHA", provider);
109-
} else {
110-
return MessageDigest.getInstance("SHA");
111-
}
95+
return MessageDigest.getInstance("SHA");
96+
11297
} catch (NoSuchAlgorithmException e) {
113-
throw new RuntimeException("Unable to get instance of SHA message digest in DigestUtils" + e.getMessage());
98+
throw new RuntimeException(e.getMessage());
11499
}
115100
}
116101

@@ -199,14 +184,5 @@ public static String shaHex(byte[] data) {
199184
public static String shaHex(String data) {
200185
return new String(Hex.encodeHex(sha(data)));
201186
}
202-
203-
/**
204-
* Allows for the replacement of the default Provider from which the DigestUtils
205-
* retrieves the implementations of MD5 and SHA.
206-
*
207-
* @param provider an instance of a Provider
208-
*/
209-
public static void setProvider(Provider pProvider) {
210-
provider = pProvider;
211-
}
187+
212188
}

src/test/org/apache/commons/codec/digest/DigestUtilsTest.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,4 @@ public void testShaHex() {
146146
+ "hijkijkljklmklmnlmnomnopnopq"));
147147
}
148148

149-
public void testMd5NoAvailable() {
150-
DigestUtils.setProvider( Security.getProviders()[3]);
151-
152-
try {
153-
DigestUtils.md5("test");
154-
fail( "The provider does not supply the MD5 algorithm, this operation should have failed");
155-
} catch( RuntimeException re ) {
156-
157-
}
158-
159-
}
160-
161-
public void testSHANoAvailable() {
162-
DigestUtils.setProvider( Security.getProviders()[3]);
163-
164-
try {
165-
DigestUtils.sha("test");
166-
fail( "The provider does not supply the SHA algorithm, this operation should have failed");
167-
} catch( RuntimeException re ) {
168-
169-
}
170-
171-
}
172149
}

0 commit comments

Comments
 (0)