forked from I2P_Developers/i2p.i2p
AsyncFortunaRandomSource: Refactor refiller for concurrent and shutdown
Add shutdown hook for FortunaRandomSource
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user