I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 824d5a0d authored by zzz's avatar zzz
Browse files

javadocs

parent 34973371
No related branches found
No related tags found
No related merge requests found
......@@ -914,9 +914,20 @@ public class DataHelper {
return c;
}
/**
* This is different than InputStream.read(target), in that it
* does repeated reads until the full data is received.
*/
public static int read(InputStream in, byte target[]) throws IOException {
return read(in, target, 0, target.length);
}
/**
* This is different than InputStream.read(target, offset, length), in that it
* returns the new offset (== old offset + bytes read).
* It also does repeated reads until the full data is received.
* @return the new offset (== old offset + bytes read)
*/
public static int read(InputStream in, byte target[], int offset, int length) throws IOException {
int cur = offset;
while (cur < length) {
......
......@@ -28,7 +28,10 @@ public class Destination extends KeysAndCert {
fromBase64(s);
}
/** deprecated, used only by Packet.java in streaming */
/**
* deprecated, used only by Packet.java in streaming
* @return the written length (NOT the new offset)
*/
public int writeBytes(byte target[], int offset) {
int cur = offset;
System.arraycopy(_publicKey.getData(), 0, target, cur, PublicKey.KEYSIZE_BYTES);
......
......@@ -93,6 +93,10 @@ public class Payload extends DataStructureImpl {
if (_log.shouldLog(Log.DEBUG))
_log.debug("wrote payload: " + _encryptedData.length);
}
/**
* @return the written length (NOT the new offset)
*/
public int writeBytes(byte target[], int offset) {
if (_encryptedData == null) throw new IllegalStateException("Not yet encrypted. Please set the encrypted data");
DataHelper.toLong(target, offset, 4, _encryptedData.length);
......
......@@ -23,7 +23,7 @@ import net.i2p.crypto.EntropyHarvester;
*
*/
public class FortunaRandomSource extends RandomSource implements EntropyHarvester {
private AsyncFortunaStandalone _fortuna;
private final AsyncFortunaStandalone _fortuna;
private double _nextGaussian;
private boolean _haveNextGaussian;
......@@ -210,6 +210,7 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
_fortuna.addRandomBytes(data, offset, len);
}
/*****
public static void main(String args[]) {
try {
RandomSource rand = I2PAppContext.getGlobalContext().random();
......@@ -231,4 +232,5 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
System.out.println("Compressed size of 1MB: " + compressed.length);
} catch (Exception e) { e.printStackTrace(); }
}
*****/
}
......@@ -25,18 +25,23 @@ import net.i2p.data.Base64;
* @author jrandom
*/
public class RandomSource extends SecureRandom implements EntropyHarvester {
private Log _log;
private EntropyHarvester _entropyHarvester;
protected I2PAppContext _context;
private final EntropyHarvester _entropyHarvester;
protected final I2PAppContext _context;
public RandomSource(I2PAppContext context) {
super();
_context = context;
_log = context.logManager().getLog(RandomSource.class);
// when we replace to have hooks for fortuna (etc), replace with
// a factory (or just a factory method)
_entropyHarvester = this;
}
/**
* Singleton for whatever PRNG i2p uses.
* Same as I2PAppContext.getGlobalContext().random();
* use context.random() if you have a context already.
* @return I2PAppContext.getGlobalContext().random()
*/
public static RandomSource getInstance() {
return I2PAppContext.getGlobalContext().random();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment