forked from I2P_Developers/i2p.i2p
SHA256Generator: Don't fall back to Sha256Standalone,
SHA-256 support must now be in the JRE. Deprecate all uses of Sha256Standalone, schedule for removal in 0.9.27. This will require a new Syndie release.
This commit is contained in:
@ -51,7 +51,9 @@ package gnu.crypto.hash;
|
||||
* See SHA256Generator for more information.
|
||||
*
|
||||
* @version $Revision: 1.1 $
|
||||
* @deprecated to be removed in 0.9.27
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class BaseHashStandalone implements IMessageDigestStandalone {
|
||||
|
||||
// Constants and variables
|
||||
|
@ -54,7 +54,9 @@ package gnu.crypto.hash;
|
||||
* See SHA256Generator for more information.
|
||||
*
|
||||
* @version $Revision: 1.1 $
|
||||
* @deprecated to be removed in 0.9.27
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IMessageDigestStandalone extends Cloneable {
|
||||
|
||||
// Constants
|
||||
|
@ -64,7 +64,9 @@ package gnu.crypto.hash;
|
||||
* See SHA256Generator for more information.
|
||||
*
|
||||
* @version $Revision: 1.2 $
|
||||
* @deprecated to be removed in 0.9.27
|
||||
*/
|
||||
@Deprecated
|
||||
public class Sha256Standalone extends BaseHashStandalone {
|
||||
// Constants and variables
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.i2p.crypto;
|
||||
|
||||
import gnu.crypto.hash.Sha256Standalone;
|
||||
|
||||
import java.security.DigestException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -14,25 +12,13 @@ import net.i2p.data.Hash;
|
||||
* Defines a wrapper for SHA-256 operation.
|
||||
*
|
||||
* As of release 0.8.7, uses java.security.MessageDigest by default.
|
||||
* If that is unavailable, it uses
|
||||
* As of release 0.9.25, uses only MessageDigest.
|
||||
* GNU-Crypto {@link gnu.crypto.hash.Sha256Standalone}
|
||||
* is deprecated.
|
||||
*/
|
||||
public final class SHA256Generator {
|
||||
private final LinkedBlockingQueue<MessageDigest> _digests;
|
||||
|
||||
private static final boolean _useGnu;
|
||||
|
||||
static {
|
||||
boolean useGnu = false;
|
||||
try {
|
||||
MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
useGnu = true;
|
||||
System.out.println("INFO: Using GNU SHA-256");
|
||||
}
|
||||
_useGnu = useGnu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context unused
|
||||
*/
|
||||
@ -96,45 +82,14 @@ public final class SHA256Generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new MessageDigest from the system libs unless unavailable
|
||||
* in this JVM, in that case return a wrapped GNU Sha256Standalone
|
||||
* Return a new MessageDigest from the system libs.
|
||||
* @since 0.8.7, public since 0.8.8 for FortunaStandalone
|
||||
*/
|
||||
public static MessageDigest getDigestInstance() {
|
||||
if (!_useGnu) {
|
||||
try {
|
||||
return MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {}
|
||||
}
|
||||
return new GnuMessageDigest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to make Sha256Standalone a MessageDigest
|
||||
* @since 0.8.7
|
||||
*/
|
||||
private static class GnuMessageDigest extends MessageDigest {
|
||||
private final Sha256Standalone _gnu;
|
||||
|
||||
protected GnuMessageDigest() {
|
||||
super("SHA-256");
|
||||
_gnu = new Sha256Standalone();
|
||||
}
|
||||
|
||||
protected byte[] engineDigest() {
|
||||
return _gnu.digest();
|
||||
}
|
||||
|
||||
protected void engineReset() {
|
||||
_gnu.reset();
|
||||
}
|
||||
|
||||
protected void engineUpdate(byte input) {
|
||||
_gnu.update(input);
|
||||
}
|
||||
|
||||
protected void engineUpdate(byte[] input, int offset, int len) {
|
||||
_gnu.update(input, offset, len);
|
||||
try {
|
||||
return MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1324,8 +1324,9 @@ public class DataHelper {
|
||||
*
|
||||
* @param hash null OK
|
||||
* @return null on EOF
|
||||
* @deprecated use MessageDigest version
|
||||
* @deprecated use MessageDigest version to be removed in 0.9.27
|
||||
*/
|
||||
@Deprecated
|
||||
public static String readLine(InputStream in, Sha256Standalone hash) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
boolean ok = readLine(in, buf, hash);
|
||||
@ -1380,7 +1381,7 @@ public class DataHelper {
|
||||
*
|
||||
* @return true if the line was read, false if eof was reached on an empty line
|
||||
* (returns true for non-empty last line without a newline)
|
||||
* @deprecated use StringBuilder / MessageDigest version
|
||||
* @deprecated use StringBuilder / MessageDigest version, to be removed in 0.9.27
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean readLine(InputStream in, StringBuffer buf, Sha256Standalone hash) throws IOException {
|
||||
@ -1420,8 +1421,9 @@ public class DataHelper {
|
||||
* @param hash null OK
|
||||
* @return true if the line was read, false if eof was reached on an empty line
|
||||
* (returns true for non-empty last line without a newline)
|
||||
* @deprecated use MessageDigest version
|
||||
* @deprecated use MessageDigest version, to be removed in 0.9.27
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean readLine(InputStream in, StringBuilder buf, Sha256Standalone hash) throws IOException {
|
||||
int c = -1;
|
||||
int i = 0;
|
||||
@ -1463,8 +1465,9 @@ public class DataHelper {
|
||||
|
||||
/**
|
||||
* update the hash along the way
|
||||
* @deprecated use MessageDigest version
|
||||
* @deprecated use MessageDigest version, to be removed in 0.9.27
|
||||
*/
|
||||
@Deprecated
|
||||
public static void write(OutputStream out, byte data[], Sha256Standalone hash) throws IOException {
|
||||
hash.update(data);
|
||||
out.write(data);
|
||||
|
Reference in New Issue
Block a user