AsyncFortunaRandomSource: Refactor refiller for concurrent and shutdown

Add shutdown hook for FortunaRandomSource
This commit is contained in:
zzz
2011-06-16 12:42:25 +00:00
parent 20ad7a44a7
commit 518fdd8c03
4 changed files with 95 additions and 70 deletions

View File

@@ -44,6 +44,14 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
_haveNextGaussian = false;
}
/**
* Note - methods may hang or NPE or throw IllegalStateExceptions after this
* @since 0.8.8
*/
public void shutdown() {
_fortuna.shutdown();
}
@Override
public synchronized void setSeed(byte buf[]) {
_fortuna.addRandomBytes(buf);

View File

@@ -28,6 +28,12 @@ public class RandomSource extends SecureRandom implements EntropyHarvester {
private final EntropyHarvester _entropyHarvester;
protected final I2PAppContext _context;
/**
* Deprecated - do not instantiate this directly, as you won't get the
* good one (Fortuna). Use getInstance() or
* I2PAppContext.getGlobalContext().random() to get the FortunaRandomSource
* instance.
*/
public RandomSource(I2PAppContext context) {
super();
_context = context;
@@ -202,10 +208,4 @@ public class RandomSource extends SecureRandom implements EntropyHarvester {
rs.saveSeed();
}
}
// noop
private static class DummyEntropyHarvester implements EntropyHarvester {
public void feedEntropy(String source, long data, int bitoffset, int bits) {}
public void feedEntropy(String source, byte[] data, int offset, int len) {}
}
}