diff options
author | Mark Wielaard <mark@klomp.org> | 2006-04-12 12:50:07 +0000 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2006-04-12 12:50:07 +0000 |
commit | e2fcada9ec7e995d6c6bcbbd1e10bcb4b99695a4 (patch) | |
tree | 6e6f6d53efdddae1666fe3a1851d2cfa824b12a9 /java/security | |
parent | b90cc775e4018e9eb6f9c9edafcdb91b33272f04 (diff) | |
download | classpath-e2fcada9ec7e995d6c6bcbbd1e10bcb4b99695a4.tar.gz |
* java/security/SecureRandom.java (algorithm): New private field.
(SecureRandom): Initialize algorithm.
(SecureRandom(SecureRandomSpi,Provider,String)): New private
constructor.
(getInstance): Call 3 argument constructor.
(getAlgorithm): New method.
Diffstat (limited to 'java/security')
-rw-r--r-- | java/security/SecureRandom.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/java/security/SecureRandom.java b/java/security/SecureRandom.java index 0d892253c..5ac9a4a8c 100644 --- a/java/security/SecureRandom.java +++ b/java/security/SecureRandom.java @@ -1,5 +1,6 @@ /* SecureRandom.java --- Secure Random class implementation - Copyright (C) 1999, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2002, 2003, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -71,6 +72,7 @@ public class SecureRandom extends Random int randomBytesUsed = 0; SecureRandomSpi secureRandomSpi = null; byte[] state = null; + private String algorithm; // Constructors. // ------------------------------------------------------------------------ @@ -111,6 +113,7 @@ public class SecureRandom extends Random secureRandomSpi = (SecureRandomSpi) Class. forName(classname).newInstance(); provider = p[i]; + algorithm = key.substring(13); // Minus SecureRandom. return; } catch (ThreadDeath death) @@ -128,6 +131,7 @@ public class SecureRandom extends Random // Nothing found. Fall back to SHA1PRNG secureRandomSpi = new Sha160RandomSpi(); + algorithm = "Sha160"; } /** @@ -159,8 +163,18 @@ public class SecureRandom extends Random */ protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider) { + this(secureRandomSpi, provider, "unknown"); + } + + /** + * Private constructor called from the getInstance() method. + */ + private SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider, + String algorithm) + { this.secureRandomSpi = secureRandomSpi; this.provider = provider; + this.algorithm = algorithm; } // Class methods. @@ -243,7 +257,7 @@ public class SecureRandom extends Random { return new SecureRandom((SecureRandomSpi) Engine.getInstance(SECURE_RANDOM, algorithm, provider), - provider); + provider, algorithm); } catch (java.lang.reflect.InvocationTargetException ite) { @@ -269,6 +283,18 @@ public class SecureRandom extends Random } /** + * Returns the algorithm name used or "unknown" when the algorithm + * used couldn't be determined (as when constructed by the protected + * 2 argument constructor). + * + * @since 1.5 + */ + public String getAlgorithm() + { + return algorithm; + } + + /** Seeds the SecureRandom. The class is re-seeded for each call and each seed builds on the previous seed so as not to weaken security. |