and another bunch
This commit is contained in:
@ -69,7 +69,8 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
_cumulativePaddingStripped = 0;
|
_cumulativePaddingStripped = 0;
|
||||||
_eofFound = false;
|
_eofFound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
while ((!_eofFound) && (_decryptedSize <= 0)) {
|
while ((!_eofFound) && (_decryptedSize <= 0)) {
|
||||||
refill();
|
refill();
|
||||||
@ -87,11 +88,13 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
+ "/" + _cumulativeRead + "... impossible");
|
+ "/" + _cumulativeRead + "... impossible");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int read(byte dest[]) throws IOException {
|
public int read(byte dest[]) throws IOException {
|
||||||
return read(dest, 0, dest.length);
|
return read(dest, 0, dest.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int read(byte dest[], int off, int len) throws IOException {
|
public int read(byte dest[], int off, int len) throws IOException {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
int val = read();
|
int val = read();
|
||||||
@ -120,7 +123,8 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
_log.debug("Read the full buffer of size " + len);
|
_log.debug("Read the full buffer of size " + len);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long skip(long numBytes) throws IOException {
|
public long skip(long numBytes) throws IOException {
|
||||||
for (long l = 0; l < numBytes; l++) {
|
for (long l = 0; l < numBytes; l++) {
|
||||||
int val = read();
|
int val = read();
|
||||||
@ -128,11 +132,13 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
return numBytes;
|
return numBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int available() throws IOException {
|
public int available() throws IOException {
|
||||||
return _decryptedSize;
|
return _decryptedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
in.close();
|
in.close();
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
@ -140,14 +146,17 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
+ _cumulativePrepared + "/" + _cumulativePaddingStripped + "] remaining [" + _decryptedSize + " ready, "
|
+ _cumulativePrepared + "/" + _cumulativePaddingStripped + "] remaining [" + _decryptedSize + " ready, "
|
||||||
+ _writesSinceDecrypt + " still encrypted]");
|
+ _writesSinceDecrypt + " still encrypted]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void mark(int readLimit) { // nop
|
public void mark(int readLimit) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void reset() throws IOException {
|
public void reset() throws IOException {
|
||||||
throw new IOException("Reset not supported");
|
throw new IOException("Reset not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean markSupported() {
|
public boolean markSupported() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -62,25 +62,29 @@ public class AESOutputStream extends FilterOutputStream {
|
|||||||
_writeBlock = new byte[BLOCK_SIZE];
|
_writeBlock = new byte[BLOCK_SIZE];
|
||||||
_writesSinceCommit = 0;
|
_writesSinceCommit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void write(int val) throws IOException {
|
public void write(int val) throws IOException {
|
||||||
_cumulativeProvided++;
|
_cumulativeProvided++;
|
||||||
_unencryptedBuf[_writesSinceCommit++] = (byte)(val & 0xFF);
|
_unencryptedBuf[_writesSinceCommit++] = (byte)(val & 0xFF);
|
||||||
if (_writesSinceCommit == _unencryptedBuf.length)
|
if (_writesSinceCommit == _unencryptedBuf.length)
|
||||||
doFlush();
|
doFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void write(byte src[]) throws IOException {
|
public void write(byte src[]) throws IOException {
|
||||||
write(src, 0, src.length);
|
write(src, 0, src.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void write(byte src[], int off, int len) throws IOException {
|
public void write(byte src[], int off, int len) throws IOException {
|
||||||
// i'm too lazy to unroll this into the partial writes (dealing with
|
// i'm too lazy to unroll this into the partial writes (dealing with
|
||||||
// wrapping around the buffer size)
|
// wrapping around the buffer size)
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
write(src[i+off]);
|
write(src[i+off]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
flush();
|
flush();
|
||||||
out.close();
|
out.close();
|
||||||
@ -88,7 +92,8 @@ public class AESOutputStream extends FilterOutputStream {
|
|||||||
_log.debug("Cumulative bytes provided to this stream / written out / padded: "
|
_log.debug("Cumulative bytes provided to this stream / written out / padded: "
|
||||||
+ _cumulativeProvided + "/" + _cumulativeWritten + "/" + _cumulativePadding);
|
+ _cumulativeProvided + "/" + _cumulativeWritten + "/" + _cumulativePadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
doFlush();
|
doFlush();
|
||||||
out.flush();
|
out.flush();
|
||||||
|
@ -40,11 +40,13 @@ public class CryptixAESEngine extends AESEngine {
|
|||||||
_log = context.logManager().getLog(CryptixAESEngine.class);
|
_log = context.logManager().getLog(CryptixAESEngine.class);
|
||||||
_cache = new CryptixAESKeyCache();
|
_cache = new CryptixAESKeyCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void encrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int length) {
|
public void encrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int length) {
|
||||||
encrypt(payload, payloadIndex, out, outIndex, sessionKey, iv, 0, length);
|
encrypt(payload, payloadIndex, out, outIndex, sessionKey, iv, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void encrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int ivOffset, int length) {
|
public void encrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int ivOffset, int length) {
|
||||||
if ( (payload == null) || (out == null) || (sessionKey == null) || (iv == null) )
|
if ( (payload == null) || (out == null) || (sessionKey == null) || (iv == null) )
|
||||||
throw new NullPointerException("invalid args to aes");
|
throw new NullPointerException("invalid args to aes");
|
||||||
@ -72,10 +74,12 @@ public class CryptixAESEngine extends AESEngine {
|
|||||||
encryptBlock(out, outIndex + x * 16, sessionKey, out, outIndex + x * 16);
|
encryptBlock(out, outIndex + x * 16, sessionKey, out, outIndex + x * 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void decrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int length) {
|
public void decrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int length) {
|
||||||
decrypt(payload, payloadIndex, out, outIndex, sessionKey, iv, 0, length);
|
decrypt(payload, payloadIndex, out, outIndex, sessionKey, iv, 0, length);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void decrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int ivOffset, int length) {
|
public void decrypt(byte payload[], int payloadIndex, byte out[], int outIndex, SessionKey sessionKey, byte iv[], int ivOffset, int length) {
|
||||||
if ((iv== null) || (payload == null) || (payload.length <= 0) || (sessionKey == null) )
|
if ((iv== null) || (payload == null) || (payload.length <= 0) || (sessionKey == null) )
|
||||||
throw new IllegalArgumentException("bad setup");
|
throw new IllegalArgumentException("bad setup");
|
||||||
@ -121,7 +125,8 @@ public class CryptixAESEngine extends AESEngine {
|
|||||||
_prevCache.release(prevA);
|
_prevCache.release(prevA);
|
||||||
_prevCache.release(curA);
|
_prevCache.release(curA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final void encryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte out[], int outIndex) {
|
public final void encryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte out[], int outIndex) {
|
||||||
if (sessionKey.getPreparedKey() == null) {
|
if (sessionKey.getPreparedKey() == null) {
|
||||||
try {
|
try {
|
||||||
@ -140,6 +145,7 @@ public class CryptixAESEngine extends AESEngine {
|
|||||||
* @param payload encrypted data
|
* @param payload encrypted data
|
||||||
* @param sessionKey private session key
|
* @param sessionKey private session key
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public final void decryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte rv[], int outIndex) {
|
public final void decryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte rv[], int outIndex) {
|
||||||
if ( (payload == null) || (rv == null) )
|
if ( (payload == null) || (rv == null) )
|
||||||
throw new IllegalArgumentException("null block args [payload=" + payload + " rv="+rv);
|
throw new IllegalArgumentException("null block args [payload=" + payload + " rv="+rv);
|
||||||
|
@ -484,7 +484,8 @@ public class DHSessionKeyBuilder {
|
|||||||
_minSize = minSize;
|
_minSize = minSize;
|
||||||
_maxSize = maxSize;
|
_maxSize = maxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
@ -14,10 +14,12 @@ public class DummyDSAEngine extends DSAEngine {
|
|||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean verifySignature(Signature signature, byte signedData[], SigningPublicKey verifyingKey) {
|
public boolean verifySignature(Signature signature, byte signedData[], SigningPublicKey verifyingKey) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Signature sign(byte data[], SigningPrivateKey signingKey) {
|
public Signature sign(byte data[], SigningPrivateKey signingKey) {
|
||||||
Signature sig = new Signature();
|
Signature sig = new Signature();
|
||||||
sig.setData(Signature.FAKE_SIGNATURE);
|
sig.setData(Signature.FAKE_SIGNATURE);
|
||||||
|
@ -46,6 +46,7 @@ public class DummyElGamalEngine extends ElGamalEngine {
|
|||||||
* @param publicKey public key encrypt to
|
* @param publicKey public key encrypt to
|
||||||
* @param data data to encrypt
|
* @param data data to encrypt
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public byte[] encrypt(byte data[], PublicKey publicKey) {
|
public byte[] encrypt(byte data[], PublicKey publicKey) {
|
||||||
if ((data == null) || (data.length >= 223))
|
if ((data == null) || (data.length >= 223))
|
||||||
throw new IllegalArgumentException("Data to encrypt must be < 223 bytes at the moment");
|
throw new IllegalArgumentException("Data to encrypt must be < 223 bytes at the moment");
|
||||||
@ -72,6 +73,7 @@ public class DummyElGamalEngine extends ElGamalEngine {
|
|||||||
* @param privateKey private key to decrypt with
|
* @param privateKey private key to decrypt with
|
||||||
* @return unencrypted data
|
* @return unencrypted data
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public byte[] decrypt(byte encrypted[], PrivateKey privateKey) {
|
public byte[] decrypt(byte encrypted[], PrivateKey privateKey) {
|
||||||
if ((encrypted == null) || (encrypted.length > 514))
|
if ((encrypted == null) || (encrypted.length > 514))
|
||||||
throw new IllegalArgumentException("Data to decrypt must be <= 514 bytes at the moment");
|
throw new IllegalArgumentException("Data to decrypt must be <= 514 bytes at the moment");
|
||||||
|
@ -14,6 +14,7 @@ public class DummyPooledRandomSource extends PooledRandomSource {
|
|||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void initializePool(I2PAppContext context) {
|
protected void initializePool(I2PAppContext context) {
|
||||||
_pool = new RandomSource[POOL_SIZE];
|
_pool = new RandomSource[POOL_SIZE];
|
||||||
for (int i = 0; i < POOL_SIZE; i++) {
|
for (int i = 0; i < POOL_SIZE; i++) {
|
||||||
@ -40,6 +41,7 @@ public class DummyPooledRandomSource extends PooledRandomSource {
|
|||||||
* thats what it has been used for.
|
* thats what it has been used for.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int nextInt(int n) {
|
public int nextInt(int n) {
|
||||||
if (n == 0) return 0;
|
if (n == 0) return 0;
|
||||||
int val = _prng.nextInt(n);
|
int val = _prng.nextInt(n);
|
||||||
@ -52,6 +54,7 @@ public class DummyPooledRandomSource extends PooledRandomSource {
|
|||||||
* Like the modified nextInt, nextLong(n) returns a random number from 0 through n,
|
* Like the modified nextInt, nextLong(n) returns a random number from 0 through n,
|
||||||
* including 0, excluding n.
|
* including 0, excluding n.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public long nextLong(long n) {
|
public long nextLong(long n) {
|
||||||
long v = _prng.nextLong();
|
long v = _prng.nextLong();
|
||||||
if (v < 0) v = 0 - v;
|
if (v < 0) v = 0 - v;
|
||||||
@ -63,36 +66,43 @@ public class DummyPooledRandomSource extends PooledRandomSource {
|
|||||||
* override as synchronized, for those JVMs that don't always pull via
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean nextBoolean() { return _prng.nextBoolean(); }
|
public boolean nextBoolean() { return _prng.nextBoolean(); }
|
||||||
/**
|
/**
|
||||||
* override as synchronized, for those JVMs that don't always pull via
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void nextBytes(byte buf[]) { _prng.nextBytes(buf); }
|
public void nextBytes(byte buf[]) { _prng.nextBytes(buf); }
|
||||||
/**
|
/**
|
||||||
* override as synchronized, for those JVMs that don't always pull via
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public double nextDouble() { return _prng.nextDouble(); }
|
public double nextDouble() { return _prng.nextDouble(); }
|
||||||
/**
|
/**
|
||||||
* override as synchronized, for those JVMs that don't always pull via
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public float nextFloat() { return _prng.nextFloat(); }
|
public float nextFloat() { return _prng.nextFloat(); }
|
||||||
/**
|
/**
|
||||||
* override as synchronized, for those JVMs that don't always pull via
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public double nextGaussian() { return _prng.nextGaussian(); }
|
public double nextGaussian() { return _prng.nextGaussian(); }
|
||||||
/**
|
/**
|
||||||
* override as synchronized, for those JVMs that don't always pull via
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int nextInt() { return _prng.nextInt(); }
|
public int nextInt() { return _prng.nextInt(); }
|
||||||
/**
|
/**
|
||||||
* override as synchronized, for those JVMs that don't always pull via
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public long nextLong() { return _prng.nextLong(); }
|
public long nextLong() { return _prng.nextLong(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import org.bouncycastle.crypto.macs.HMac;
|
|||||||
public class HMAC256Generator extends HMACGenerator {
|
public class HMAC256Generator extends HMACGenerator {
|
||||||
public HMAC256Generator(I2PAppContext context) { super(context); }
|
public HMAC256Generator(I2PAppContext context) { super(context); }
|
||||||
|
|
||||||
|
@Override
|
||||||
protected HMac acquire() {
|
protected HMac acquire() {
|
||||||
synchronized (_available) {
|
synchronized (_available) {
|
||||||
if (_available.size() > 0)
|
if (_available.size() > 0)
|
||||||
@ -30,8 +31,11 @@ public class HMAC256Generator extends HMACGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class Sha256ForMAC extends Sha256Standalone implements Digest {
|
private class Sha256ForMAC extends Sha256Standalone implements Digest {
|
||||||
|
@Override
|
||||||
public String getAlgorithmName() { return "sha256 for hmac"; }
|
public String getAlgorithmName() { return "sha256 for hmac"; }
|
||||||
|
@Override
|
||||||
public int getDigestSize() { return 32; }
|
public int getDigestSize() { return 32; }
|
||||||
|
@Override
|
||||||
public int doFinal(byte[] out, int outOff) {
|
public int doFinal(byte[] out, int outOff) {
|
||||||
byte rv[] = digest();
|
byte rv[] = digest();
|
||||||
System.arraycopy(rv, 0, out, outOff, rv.length);
|
System.arraycopy(rv, 0, out, outOff, rv.length);
|
||||||
|
@ -97,6 +97,7 @@ public final class SHA1 extends MessageDigest implements Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Clones this object.
|
* Clones this object.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Object clone() throws CloneNotSupportedException {
|
public Object clone() throws CloneNotSupportedException {
|
||||||
SHA1 that = (SHA1)super.clone();
|
SHA1 that = (SHA1)super.clone();
|
||||||
that.pad = (byte[])this.pad.clone();
|
that.pad = (byte[])this.pad.clone();
|
||||||
@ -113,6 +114,7 @@ public final class SHA1 extends MessageDigest implements Cloneable {
|
|||||||
* <code>java.security.MessageDigestSpi</code>.
|
* <code>java.security.MessageDigestSpi</code>.
|
||||||
* @return the digest length in bytes.
|
* @return the digest length in bytes.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int engineGetDigestLength() {
|
public int engineGetDigestLength() {
|
||||||
return HASH_LENGTH;
|
return HASH_LENGTH;
|
||||||
}
|
}
|
||||||
@ -123,6 +125,7 @@ public final class SHA1 extends MessageDigest implements Cloneable {
|
|||||||
* Overrides the protected abstract method of
|
* Overrides the protected abstract method of
|
||||||
* <code>java.security.MessageDigestSpi</code>.
|
* <code>java.security.MessageDigestSpi</code>.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void engineReset() {
|
protected void engineReset() {
|
||||||
int i = 60;
|
int i = 60;
|
||||||
do {
|
do {
|
||||||
@ -179,6 +182,7 @@ public final class SHA1 extends MessageDigest implements Cloneable {
|
|||||||
* @param offset the offset to start from in the array of bytes.
|
* @param offset the offset to start from in the array of bytes.
|
||||||
* @param len the number of bytes to use, starting at offset.
|
* @param len the number of bytes to use, starting at offset.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void engineUpdate(byte[] input, int offset, int len) {
|
public void engineUpdate(byte[] input, int offset, int len) {
|
||||||
if (offset >= 0 && len >= 0 && offset + len <= input.length) {
|
if (offset >= 0 && len >= 0 && offset + len <= input.length) {
|
||||||
bytes += len;
|
bytes += len;
|
||||||
@ -234,6 +238,7 @@ public final class SHA1 extends MessageDigest implements Cloneable {
|
|||||||
* java.security.MessageDigestSpi.
|
* java.security.MessageDigestSpi.
|
||||||
* @return the length of the digest stored in the output buffer.
|
* @return the length of the digest stored in the output buffer.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public byte[] engineDigest() {
|
public byte[] engineDigest() {
|
||||||
try {
|
try {
|
||||||
final byte hashvalue[] = new byte[HASH_LENGTH];
|
final byte hashvalue[] = new byte[HASH_LENGTH];
|
||||||
@ -264,6 +269,7 @@ public final class SHA1 extends MessageDigest implements Cloneable {
|
|||||||
* length.
|
* length.
|
||||||
* @return the length of the digest stored in the output buffer.
|
* @return the length of the digest stored in the output buffer.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int engineDigest(byte[] hashvalue, int offset, final int len)
|
public int engineDigest(byte[] hashvalue, int offset, final int len)
|
||||||
throws DigestException {
|
throws DigestException {
|
||||||
if (len >= HASH_LENGTH) {
|
if (len >= HASH_LENGTH) {
|
||||||
|
@ -75,6 +75,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
private TransientSessionKeyManager() { this(null); }
|
private TransientSessionKeyManager() { this(null); }
|
||||||
|
|
||||||
private class CleanupEvent implements SimpleTimer.TimedEvent {
|
private class CleanupEvent implements SimpleTimer.TimedEvent {
|
||||||
|
@Override
|
||||||
public void timeReached() {
|
public void timeReached() {
|
||||||
long beforeExpire = _context.clock().now();
|
long beforeExpire = _context.clock().now();
|
||||||
int expired = aggressiveExpire();
|
int expired = aggressiveExpire();
|
||||||
@ -130,6 +131,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* or null if a new session key should be generated.
|
* or null if a new session key should be generated.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public SessionKey getCurrentKey(PublicKey target) {
|
public SessionKey getCurrentKey(PublicKey target) {
|
||||||
OutboundSession sess = getSession(target);
|
OutboundSession sess = getSession(target);
|
||||||
if (sess == null) return null;
|
if (sess == null) return null;
|
||||||
@ -151,6 +153,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* when to expire that key begin with this call.
|
* when to expire that key begin with this call.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void createSession(PublicKey target, SessionKey key) {
|
public void createSession(PublicKey target, SessionKey key) {
|
||||||
OutboundSession sess = new OutboundSession(target);
|
OutboundSession sess = new OutboundSession(target);
|
||||||
sess.setCurrentKey(key);
|
sess.setCurrentKey(key);
|
||||||
@ -164,6 +167,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* NOT be used)
|
* NOT be used)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public SessionTag consumeNextAvailableTag(PublicKey target, SessionKey key) {
|
public SessionTag consumeNextAvailableTag(PublicKey target, SessionKey key) {
|
||||||
OutboundSession sess = getSession(target);
|
OutboundSession sess = getSession(target);
|
||||||
if (sess == null) {
|
if (sess == null) {
|
||||||
@ -187,6 +191,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* have been confirmed and are available
|
* have been confirmed and are available
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getAvailableTags(PublicKey target, SessionKey key) {
|
public int getAvailableTags(PublicKey target, SessionKey key) {
|
||||||
OutboundSession sess = getSession(target);
|
OutboundSession sess = getSession(target);
|
||||||
if (sess == null) { return 0; }
|
if (sess == null) { return 0; }
|
||||||
@ -200,6 +205,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* Determine how long the available tags will be available for before expiring, in
|
* Determine how long the available tags will be available for before expiring, in
|
||||||
* milliseconds
|
* milliseconds
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public long getAvailableTimeLeft(PublicKey target, SessionKey key) {
|
public long getAvailableTimeLeft(PublicKey target, SessionKey key) {
|
||||||
OutboundSession sess = getSession(target);
|
OutboundSession sess = getSession(target);
|
||||||
if (sess == null) { return 0; }
|
if (sess == null) { return 0; }
|
||||||
@ -219,6 +225,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* method after receiving an ack to a message delivering them)
|
* method after receiving an ack to a message delivering them)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void tagsDelivered(PublicKey target, SessionKey key, Set sessionTags) {
|
public void tagsDelivered(PublicKey target, SessionKey key, Set sessionTags) {
|
||||||
if (_log.shouldLog(Log.DEBUG)) {
|
if (_log.shouldLog(Log.DEBUG)) {
|
||||||
//_log.debug("Tags delivered to set " + set + " on session " + sess);
|
//_log.debug("Tags delivered to set " + set + " on session " + sess);
|
||||||
@ -241,6 +248,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* from corrupted tag sets and crashes
|
* from corrupted tag sets and crashes
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void failTags(PublicKey target) {
|
public void failTags(PublicKey target) {
|
||||||
removeSession(target);
|
removeSession(target);
|
||||||
}
|
}
|
||||||
@ -249,6 +257,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* Accept the given tags and associate them with the given key for decryption
|
* Accept the given tags and associate them with the given key for decryption
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void tagsReceived(SessionKey key, Set sessionTags) {
|
public void tagsReceived(SessionKey key, Set sessionTags) {
|
||||||
int overage = 0;
|
int overage = 0;
|
||||||
TagSet tagSet = new TagSet(sessionTags, key, _context.clock().now());
|
TagSet tagSet = new TagSet(sessionTags, key, _context.clock().now());
|
||||||
@ -360,6 +369,7 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
* matches
|
* matches
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public SessionKey consumeTag(SessionTag tag) {
|
public SessionKey consumeTag(SessionTag tag) {
|
||||||
if (false) aggressiveExpire();
|
if (false) aggressiveExpire();
|
||||||
synchronized (_inboundTagSets) {
|
synchronized (_inboundTagSets) {
|
||||||
@ -711,7 +721,8 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Exception getCreatedBy() { return _createdBy; }
|
public Exception getCreatedBy() { return _createdBy; }
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
long rv = 0;
|
long rv = 0;
|
||||||
if (_key != null) rv = rv * 7 + _key.hashCode();
|
if (_key != null) rv = rv * 7 + _key.hashCode();
|
||||||
@ -719,7 +730,8 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
// no need to hashCode the tags, key + date should be enough
|
// no need to hashCode the tags, key + date should be enough
|
||||||
return (int) rv;
|
return (int) rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if ((o == null) || !(o instanceof TagSet)) return false;
|
if ((o == null) || !(o instanceof TagSet)) return false;
|
||||||
TagSet ts = (TagSet) o;
|
TagSet ts = (TagSet) o;
|
||||||
|
@ -42,13 +42,15 @@ public class Address extends DataStructureImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException,
|
public void readBytes(InputStream in) throws DataFormatException,
|
||||||
IOException {
|
IOException {
|
||||||
_hostname = DataHelper.readString(in);
|
_hostname = DataHelper.readString(in);
|
||||||
_destination = new Destination();
|
_destination = new Destination();
|
||||||
_destination.readBytes(in);
|
_destination.readBytes(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException,
|
public void writeBytes(OutputStream out) throws DataFormatException,
|
||||||
IOException {
|
IOException {
|
||||||
if ((_hostname == null) || (_destination == null))
|
if ((_hostname == null) || (_destination == null))
|
||||||
@ -57,6 +59,7 @@ public class Address extends DataStructureImpl {
|
|||||||
_destination.writeBytes(out);
|
_destination.writeBytes(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof Address)) return false;
|
if ((obj == null) || !(obj instanceof Address)) return false;
|
||||||
Address addr = (Address) obj;
|
Address addr = (Address) obj;
|
||||||
@ -64,11 +67,13 @@ public class Address extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(_destination, addr.getDestination());
|
&& DataHelper.eq(_destination, addr.getDestination());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(getHostname())
|
return DataHelper.hashCode(getHostname())
|
||||||
+ DataHelper.hashCode(getDestination());
|
+ DataHelper.hashCode(getDestination());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[Address: ");
|
buf.append("[Address: ");
|
||||||
|
@ -53,7 +53,8 @@ public class ByteArray implements Serializable, Comparable {
|
|||||||
public void setValid(int valid) { _valid = valid; }
|
public void setValid(int valid) { _valid = valid; }
|
||||||
public int getOffset() { return _offset; }
|
public int getOffset() { return _offset; }
|
||||||
public void setOffset(int offset) { _offset = offset; }
|
public void setOffset(int offset) { _offset = offset; }
|
||||||
|
|
||||||
|
@Override
|
||||||
public final boolean equals(Object o) {
|
public final boolean equals(Object o) {
|
||||||
if (o == null) return false;
|
if (o == null) return false;
|
||||||
if (o instanceof ByteArray) {
|
if (o instanceof ByteArray) {
|
||||||
@ -73,15 +74,18 @@ public class ByteArray implements Serializable, Comparable {
|
|||||||
return (llen == rlen) && DataHelper.eq(lhs, loff, rhs, roff, llen);
|
return (llen == rlen) && DataHelper.eq(lhs, loff, rhs, roff, llen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final int compareTo(Object obj) {
|
public final int compareTo(Object obj) {
|
||||||
if (obj.getClass() != getClass()) throw new ClassCastException("invalid object: " + obj);
|
if (obj.getClass() != getClass()) throw new ClassCastException("invalid object: " + obj);
|
||||||
return DataHelper.compareTo(_data, ((ByteArray)obj).getData());
|
return DataHelper.compareTo(_data, ((ByteArray)obj).getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final int hashCode() {
|
public final int hashCode() {
|
||||||
return DataHelper.hashCode(getData());
|
return DataHelper.hashCode(getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + "/" + DataHelper.toString(getData(), 32) + "." + _valid;
|
return super.toString() + "/" + DataHelper.toString(getData(), 32) + "." + _valid;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@ public class Certificate extends DataStructureImpl {
|
|||||||
public void setPayload(byte[] payload) {
|
public void setPayload(byte[] payload) {
|
||||||
_payload = payload;
|
_payload = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_type = (int) DataHelper.readLong(in, 1);
|
_type = (int) DataHelper.readLong(in, 1);
|
||||||
int length = (int) DataHelper.readLong(in, 2);
|
int length = (int) DataHelper.readLong(in, 2);
|
||||||
@ -78,7 +79,8 @@ public class Certificate extends DataStructureImpl {
|
|||||||
+ ")");
|
+ ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_type < 0) throw new DataFormatException("Invalid certificate type: " + _type);
|
if (_type < 0) throw new DataFormatException("Invalid certificate type: " + _type);
|
||||||
//if ((_type != 0) && (_payload == null)) throw new DataFormatException("Payload is required for non null type");
|
//if ((_type != 0) && (_payload == null)) throw new DataFormatException("Payload is required for non null type");
|
||||||
@ -134,17 +136,18 @@ public class Certificate extends DataStructureImpl {
|
|||||||
public int size() {
|
public int size() {
|
||||||
return 1 + 2 + (_payload != null ? _payload.length : 0);
|
return 1 + 2 + (_payload != null ? _payload.length : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof Certificate)) return false;
|
if ((object == null) || !(object instanceof Certificate)) return false;
|
||||||
Certificate cert = (Certificate) object;
|
Certificate cert = (Certificate) object;
|
||||||
return getCertificateType() == cert.getCertificateType() && DataHelper.eq(getPayload(), cert.getPayload());
|
return getCertificateType() == cert.getCertificateType() && DataHelper.eq(getPayload(), cert.getPayload());
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getCertificateType() + DataHelper.hashCode(getPayload());
|
return getCertificateType() + DataHelper.hashCode(getPayload());
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[Certificate: type: ");
|
buf.append("[Certificate: type: ");
|
||||||
|
@ -24,7 +24,8 @@ import net.i2p.util.Log;
|
|||||||
*/
|
*/
|
||||||
public abstract class DataStructureImpl implements DataStructure {
|
public abstract class DataStructureImpl implements DataStructure {
|
||||||
private final static Log _log = new Log(DataStructureImpl.class);
|
private final static Log _log = new Log(DataStructureImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toBase64() {
|
public String toBase64() {
|
||||||
byte data[] = toByteArray();
|
byte data[] = toByteArray();
|
||||||
if (data == null)
|
if (data == null)
|
||||||
@ -32,19 +33,19 @@ public abstract class DataStructureImpl implements DataStructure {
|
|||||||
|
|
||||||
return Base64.encode(data);
|
return Base64.encode(data);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void fromBase64(String data) throws DataFormatException {
|
public void fromBase64(String data) throws DataFormatException {
|
||||||
if (data == null) throw new DataFormatException("Null data passed in");
|
if (data == null) throw new DataFormatException("Null data passed in");
|
||||||
byte bytes[] = Base64.decode(data);
|
byte bytes[] = Base64.decode(data);
|
||||||
fromByteArray(bytes);
|
fromByteArray(bytes);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public Hash calculateHash() {
|
public Hash calculateHash() {
|
||||||
byte data[] = toByteArray();
|
byte data[] = toByteArray();
|
||||||
if (data != null) return SHA256Generator.getInstance().calculateHash(data);
|
if (data != null) return SHA256Generator.getInstance().calculateHash(data);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public byte[] toByteArray() {
|
public byte[] toByteArray() {
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||||
@ -58,7 +59,7 @@ public abstract class DataStructureImpl implements DataStructure {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void fromByteArray(byte data[]) throws DataFormatException {
|
public void fromByteArray(byte data[]) throws DataFormatException {
|
||||||
if (data == null) throw new DataFormatException("Null data passed in");
|
if (data == null) throw new DataFormatException("Null data passed in");
|
||||||
try {
|
try {
|
||||||
|
@ -71,7 +71,8 @@ public class Destination extends DataStructureImpl {
|
|||||||
_signingKey = key;
|
_signingKey = key;
|
||||||
__calculatedHash = null;
|
__calculatedHash = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_publicKey = new PublicKey();
|
_publicKey = new PublicKey();
|
||||||
_publicKey.readBytes(in);
|
_publicKey.readBytes(in);
|
||||||
@ -81,7 +82,8 @@ public class Destination extends DataStructureImpl {
|
|||||||
_certificate.readBytes(in);
|
_certificate.readBytes(in);
|
||||||
__calculatedHash = null;
|
__calculatedHash = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if ((_certificate == null) || (_publicKey == null) || (_signingKey == null))
|
if ((_certificate == null) || (_publicKey == null) || (_signingKey == null))
|
||||||
throw new DataFormatException("Not enough data to format the destination");
|
throw new DataFormatException("Not enough data to format the destination");
|
||||||
@ -128,6 +130,7 @@ public class Destination extends DataStructureImpl {
|
|||||||
return PublicKey.KEYSIZE_BYTES + SigningPublicKey.KEYSIZE_BYTES + _certificate.size();
|
return PublicKey.KEYSIZE_BYTES + SigningPublicKey.KEYSIZE_BYTES + _certificate.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof Destination)) return false;
|
if ((object == null) || !(object instanceof Destination)) return false;
|
||||||
Destination dst = (Destination) object;
|
Destination dst = (Destination) object;
|
||||||
@ -135,12 +138,14 @@ public class Destination extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(getSigningPublicKey(), dst.getSigningPublicKey())
|
&& DataHelper.eq(getSigningPublicKey(), dst.getSigningPublicKey())
|
||||||
&& DataHelper.eq(getPublicKey(), dst.getPublicKey());
|
&& DataHelper.eq(getPublicKey(), dst.getPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(getCertificate()) + DataHelper.hashCode(getSigningPublicKey())
|
return DataHelper.hashCode(getCertificate()) + DataHelper.hashCode(getSigningPublicKey())
|
||||||
+ DataHelper.hashCode(getPublicKey());
|
+ DataHelper.hashCode(getPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(128);
|
StringBuffer buf = new StringBuffer(128);
|
||||||
buf.append("[Destination: ");
|
buf.append("[Destination: ");
|
||||||
@ -151,7 +156,8 @@ public class Destination extends DataStructureImpl {
|
|||||||
buf.append("]");
|
buf.append("]");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Hash calculateHash() {
|
public Hash calculateHash() {
|
||||||
if (__calculatedHash == null) __calculatedHash = super.calculateHash();
|
if (__calculatedHash == null) __calculatedHash = super.calculateHash();
|
||||||
return __calculatedHash;
|
return __calculatedHash;
|
||||||
|
@ -127,6 +127,7 @@ public class Hash extends DataStructureImpl {
|
|||||||
_xorCache = null;
|
_xorCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[HASH_LENGTH];
|
_data = new byte[HASH_LENGTH];
|
||||||
_stringified = null;
|
_stringified = null;
|
||||||
@ -134,22 +135,26 @@ public class Hash extends DataStructureImpl {
|
|||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != HASH_LENGTH) throw new DataFormatException("Not enough bytes to read the hash");
|
if (read != HASH_LENGTH) throw new DataFormatException("Not enough bytes to read the hash");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_data == null) throw new DataFormatException("No data in the hash to write out");
|
if (_data == null) throw new DataFormatException("No data in the hash to write out");
|
||||||
if (_data.length != HASH_LENGTH) throw new DataFormatException("Invalid size of data in the private key");
|
if (_data.length != HASH_LENGTH) throw new DataFormatException("Invalid size of data in the private key");
|
||||||
out.write(_data);
|
out.write(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof Hash)) return false;
|
if ((obj == null) || !(obj instanceof Hash)) return false;
|
||||||
return DataHelper.eq(_data, ((Hash) obj)._data);
|
return DataHelper.eq(_data, ((Hash) obj)._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(_data);
|
return DataHelper.hashCode(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (_stringified == null) {
|
if (_stringified == null) {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
@ -165,6 +170,7 @@ public class Hash extends DataStructureImpl {
|
|||||||
return _stringified;
|
return _stringified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toBase64() {
|
public String toBase64() {
|
||||||
if (_base64ed == null) {
|
if (_base64ed == null) {
|
||||||
_base64ed = super.toBase64();
|
_base64ed = super.toBase64();
|
||||||
|
@ -111,7 +111,8 @@ public class Lease extends DataStructureImpl {
|
|||||||
if (_end == null) return true;
|
if (_end == null) return true;
|
||||||
return _end.getTime() < Clock.getInstance().now() - fudgeFactor;
|
return _end.getTime() < Clock.getInstance().now() - fudgeFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_gateway = new Hash();
|
_gateway = new Hash();
|
||||||
_gateway.readBytes(in);
|
_gateway.readBytes(in);
|
||||||
@ -119,7 +120,8 @@ public class Lease extends DataStructureImpl {
|
|||||||
_tunnelId.readBytes(in);
|
_tunnelId.readBytes(in);
|
||||||
_end = DataHelper.readDate(in);
|
_end = DataHelper.readDate(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if ((_gateway == null) || (_tunnelId == null))
|
if ((_gateway == null) || (_tunnelId == null))
|
||||||
throw new DataFormatException("Not enough data to write out a Lease");
|
throw new DataFormatException("Not enough data to write out a Lease");
|
||||||
@ -128,7 +130,8 @@ public class Lease extends DataStructureImpl {
|
|||||||
_tunnelId.writeBytes(out);
|
_tunnelId.writeBytes(out);
|
||||||
DataHelper.writeDate(out, _end);
|
DataHelper.writeDate(out, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof Lease)) return false;
|
if ((object == null) || !(object instanceof Lease)) return false;
|
||||||
Lease lse = (Lease) object;
|
Lease lse = (Lease) object;
|
||||||
@ -137,12 +140,14 @@ public class Lease extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(getGateway(), lse.getGateway());
|
&& DataHelper.eq(getGateway(), lse.getGateway());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(getEndDate()) + DataHelper.hashCode(getGateway())
|
return DataHelper.hashCode(getEndDate()) + DataHelper.hashCode(getGateway())
|
||||||
+ DataHelper.hashCode(getTunnelId());
|
+ DataHelper.hashCode(getTunnelId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(128);
|
StringBuffer buf = new StringBuffer(128);
|
||||||
buf.append("[Lease: ");
|
buf.append("[Lease: ");
|
||||||
|
@ -252,7 +252,8 @@ public class LeaseSet extends DataStructureImpl {
|
|||||||
byte rv[] = out.toByteArray();
|
byte rv[] = out.toByteArray();
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_destination = new Destination();
|
_destination = new Destination();
|
||||||
_destination.readBytes(in);
|
_destination.readBytes(in);
|
||||||
@ -273,7 +274,8 @@ public class LeaseSet extends DataStructureImpl {
|
|||||||
_signature = new Signature();
|
_signature = new Signature();
|
||||||
_signature.readBytes(in);
|
_signature.readBytes(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if ((_destination == null) || (_encryptionKey == null) || (_signingKey == null) || (_leases == null)
|
if ((_destination == null) || (_encryptionKey == null) || (_signingKey == null) || (_leases == null)
|
||||||
|| (_signature == null)) throw new DataFormatException("Not enough data to write out a LeaseSet");
|
|| (_signature == null)) throw new DataFormatException("Not enough data to write out a LeaseSet");
|
||||||
@ -299,7 +301,8 @@ public class LeaseSet extends DataStructureImpl {
|
|||||||
+ 1
|
+ 1
|
||||||
+ _leases.size() * (Hash.HASH_LENGTH + 4 + 8);
|
+ _leases.size() * (Hash.HASH_LENGTH + 4 + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof LeaseSet)) return false;
|
if ((object == null) || !(object instanceof LeaseSet)) return false;
|
||||||
LeaseSet ls = (LeaseSet) object;
|
LeaseSet ls = (LeaseSet) object;
|
||||||
@ -310,14 +313,16 @@ public class LeaseSet extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(getDestination(), ls.getDestination());
|
&& DataHelper.eq(getDestination(), ls.getDestination());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(getEncryptionKey()) +
|
return DataHelper.hashCode(getEncryptionKey()) +
|
||||||
//(int)_version +
|
//(int)_version +
|
||||||
DataHelper.hashCode(_leases) + DataHelper.hashCode(getSignature())
|
DataHelper.hashCode(_leases) + DataHelper.hashCode(getSignature())
|
||||||
+ DataHelper.hashCode(getSigningKey()) + DataHelper.hashCode(getDestination());
|
+ DataHelper.hashCode(getSigningKey()) + DataHelper.hashCode(getDestination());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(128);
|
StringBuffer buf = new StringBuffer(128);
|
||||||
buf.append("[LeaseSet: ");
|
buf.append("[LeaseSet: ");
|
||||||
|
@ -66,7 +66,8 @@ public class Payload extends DataStructureImpl {
|
|||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
int size = (int) DataHelper.readLong(in, 4);
|
int size = (int) DataHelper.readLong(in, 4);
|
||||||
if (size < 0) throw new DataFormatException("payload size out of range (" + size + ")");
|
if (size < 0) throw new DataFormatException("payload size out of range (" + size + ")");
|
||||||
@ -76,7 +77,8 @@ public class Payload extends DataStructureImpl {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("read payload: " + read + " bytes");
|
_log.debug("read payload: " + read + " bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_encryptedData == null) throw new DataFormatException("Not yet encrypted. Please set the encrypted data");
|
if (_encryptedData == null) throw new DataFormatException("Not yet encrypted. Please set the encrypted data");
|
||||||
DataHelper.writeLong(out, 4, _encryptedData.length);
|
DataHelper.writeLong(out, 4, _encryptedData.length);
|
||||||
@ -91,18 +93,21 @@ public class Payload extends DataStructureImpl {
|
|||||||
System.arraycopy(_encryptedData, 0, target, offset, _encryptedData.length);
|
System.arraycopy(_encryptedData, 0, target, offset, _encryptedData.length);
|
||||||
return 4 + _encryptedData.length;
|
return 4 + _encryptedData.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof Payload)) return false;
|
if ((object == null) || !(object instanceof Payload)) return false;
|
||||||
Payload p = (Payload) object;
|
Payload p = (Payload) object;
|
||||||
return DataHelper.eq(getUnencryptedData(), p.getUnencryptedData())
|
return DataHelper.eq(getUnencryptedData(), p.getUnencryptedData())
|
||||||
&& DataHelper.eq(getEncryptedData(), p.getEncryptedData());
|
&& DataHelper.eq(getEncryptedData(), p.getEncryptedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(getUnencryptedData());
|
return DataHelper.hashCode(getUnencryptedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (true) return "[Payload]";
|
if (true) return "[Payload]";
|
||||||
StringBuffer buf = new StringBuffer(128);
|
StringBuffer buf = new StringBuffer(128);
|
||||||
|
@ -50,29 +50,34 @@ public class PrivateKey extends DataStructureImpl {
|
|||||||
public void setData(byte[] data) {
|
public void setData(byte[] data) {
|
||||||
_data = data;
|
_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[KEYSIZE_BYTES];
|
_data = new byte[KEYSIZE_BYTES];
|
||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the private key");
|
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the private key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_data == null) throw new DataFormatException("No data in the private key to write out");
|
if (_data == null) throw new DataFormatException("No data in the private key to write out");
|
||||||
if (_data.length != KEYSIZE_BYTES)
|
if (_data.length != KEYSIZE_BYTES)
|
||||||
throw new DataFormatException("Invalid size of data in the private key [" + _data.length + "]");
|
throw new DataFormatException("Invalid size of data in the private key [" + _data.length + "]");
|
||||||
out.write(_data);
|
out.write(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof PrivateKey)) return false;
|
if ((obj == null) || !(obj instanceof PrivateKey)) return false;
|
||||||
return DataHelper.eq(_data, ((PrivateKey) obj)._data);
|
return DataHelper.eq(_data, ((PrivateKey) obj)._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(_data);
|
return DataHelper.hashCode(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[PrivateKey: ");
|
buf.append("[PrivateKey: ");
|
||||||
|
@ -53,28 +53,33 @@ public class PublicKey extends DataStructureImpl {
|
|||||||
public void setData(byte[] data) {
|
public void setData(byte[] data) {
|
||||||
_data = data;
|
_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[KEYSIZE_BYTES];
|
_data = new byte[KEYSIZE_BYTES];
|
||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the public key");
|
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the public key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_data == null) throw new DataFormatException("No data in the public key to write out");
|
if (_data == null) throw new DataFormatException("No data in the public key to write out");
|
||||||
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the public key");
|
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the public key");
|
||||||
out.write(_data);
|
out.write(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof PublicKey)) return false;
|
if ((obj == null) || !(obj instanceof PublicKey)) return false;
|
||||||
return DataHelper.eq(_data, ((PublicKey) obj)._data);
|
return DataHelper.eq(_data, ((PublicKey) obj)._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(_data);
|
return DataHelper.hashCode(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[PublicKey: ");
|
buf.append("[PublicKey: ");
|
||||||
|
@ -104,14 +104,16 @@ public class RouterAddress extends DataStructureImpl {
|
|||||||
public void setOptions(Properties options) {
|
public void setOptions(Properties options) {
|
||||||
_options = options;
|
_options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_cost = (int) DataHelper.readLong(in, 1);
|
_cost = (int) DataHelper.readLong(in, 1);
|
||||||
_expiration = DataHelper.readDate(in);
|
_expiration = DataHelper.readDate(in);
|
||||||
_transportStyle = DataHelper.readString(in);
|
_transportStyle = DataHelper.readString(in);
|
||||||
_options = DataHelper.readProperties(in);
|
_options = DataHelper.readProperties(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if ((_cost < 0) || (_transportStyle == null) || (_options == null))
|
if ((_cost < 0) || (_transportStyle == null) || (_options == null))
|
||||||
throw new DataFormatException("Not enough data to write a router address");
|
throw new DataFormatException("Not enough data to write a router address");
|
||||||
@ -120,7 +122,8 @@ public class RouterAddress extends DataStructureImpl {
|
|||||||
DataHelper.writeString(out, _transportStyle);
|
DataHelper.writeString(out, _transportStyle);
|
||||||
DataHelper.writeProperties(out, _options);
|
DataHelper.writeProperties(out, _options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof RouterAddress)) return false;
|
if ((object == null) || !(object instanceof RouterAddress)) return false;
|
||||||
RouterAddress addr = (RouterAddress) object;
|
RouterAddress addr = (RouterAddress) object;
|
||||||
@ -128,12 +131,14 @@ public class RouterAddress extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(getOptions(), addr.getOptions())
|
&& DataHelper.eq(getOptions(), addr.getOptions())
|
||||||
&& DataHelper.eq(getTransportStyle(), addr.getTransportStyle());
|
&& DataHelper.eq(getTransportStyle(), addr.getTransportStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getCost() + DataHelper.hashCode(getTransportStyle()) + DataHelper.hashCode(getExpiration())
|
return getCost() + DataHelper.hashCode(getTransportStyle()) + DataHelper.hashCode(getExpiration())
|
||||||
+ DataHelper.hashCode(getOptions());
|
+ DataHelper.hashCode(getOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[RouterAddress: ");
|
buf.append("[RouterAddress: ");
|
||||||
|
@ -73,7 +73,8 @@ public class RouterIdentity extends DataStructureImpl {
|
|||||||
public boolean isHidden() {
|
public boolean isHidden() {
|
||||||
return (_certificate != null) && (_certificate.getCertificateType() == Certificate.CERTIFICATE_TYPE_HIDDEN);
|
return (_certificate != null) && (_certificate.getCertificateType() == Certificate.CERTIFICATE_TYPE_HIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_publicKey = new PublicKey();
|
_publicKey = new PublicKey();
|
||||||
_publicKey.readBytes(in);
|
_publicKey.readBytes(in);
|
||||||
@ -83,7 +84,8 @@ public class RouterIdentity extends DataStructureImpl {
|
|||||||
_certificate.readBytes(in);
|
_certificate.readBytes(in);
|
||||||
__calculatedHash = null;
|
__calculatedHash = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if ((_certificate == null) || (_publicKey == null) || (_signingKey == null))
|
if ((_certificate == null) || (_publicKey == null) || (_signingKey == null))
|
||||||
throw new DataFormatException("Not enough data to format the router identity");
|
throw new DataFormatException("Not enough data to format the router identity");
|
||||||
@ -91,7 +93,8 @@ public class RouterIdentity extends DataStructureImpl {
|
|||||||
_signingKey.writeBytes(out);
|
_signingKey.writeBytes(out);
|
||||||
_certificate.writeBytes(out);
|
_certificate.writeBytes(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof RouterIdentity)) return false;
|
if ((object == null) || !(object instanceof RouterIdentity)) return false;
|
||||||
RouterIdentity ident = (RouterIdentity) object;
|
RouterIdentity ident = (RouterIdentity) object;
|
||||||
@ -99,12 +102,14 @@ public class RouterIdentity extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(getSigningPublicKey(), ident.getSigningPublicKey())
|
&& DataHelper.eq(getSigningPublicKey(), ident.getSigningPublicKey())
|
||||||
&& DataHelper.eq(getPublicKey(), ident.getPublicKey());
|
&& DataHelper.eq(getPublicKey(), ident.getPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(getCertificate()) + DataHelper.hashCode(getSigningPublicKey())
|
return DataHelper.hashCode(getCertificate()) + DataHelper.hashCode(getSigningPublicKey())
|
||||||
+ DataHelper.hashCode(getPublicKey());
|
+ DataHelper.hashCode(getPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[RouterIdentity: ");
|
buf.append("[RouterIdentity: ");
|
||||||
@ -115,7 +120,8 @@ public class RouterIdentity extends DataStructureImpl {
|
|||||||
buf.append("]");
|
buf.append("]");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Hash calculateHash() {
|
public Hash calculateHash() {
|
||||||
return getHash();
|
return getHash();
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,8 @@ public class RouterInfo extends DataStructureImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public synchronized void readBytes(InputStream in) throws DataFormatException, IOException {
|
public synchronized void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_identity = new RouterIdentity();
|
_identity = new RouterIdentity();
|
||||||
_identity.readBytes(in);
|
_identity.readBytes(in);
|
||||||
@ -515,7 +516,8 @@ public class RouterInfo extends DataStructureImpl {
|
|||||||
|
|
||||||
//_log.debug("Read routerInfo: " + toString());
|
//_log.debug("Read routerInfo: " + toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public synchronized void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public synchronized void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_identity == null) throw new DataFormatException("Missing identity");
|
if (_identity == null) throw new DataFormatException("Missing identity");
|
||||||
if (_published < 0) throw new DataFormatException("Invalid published date: " + _published);
|
if (_published < 0) throw new DataFormatException("Invalid published date: " + _published);
|
||||||
@ -530,7 +532,8 @@ public class RouterInfo extends DataStructureImpl {
|
|||||||
//_log.debug("Writing routerInfo [len=" + data.length + "]: " + toString());
|
//_log.debug("Writing routerInfo [len=" + data.length + "]: " + toString());
|
||||||
out.write(data);
|
out.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object == null) || !(object instanceof RouterInfo)) return false;
|
if ((object == null) || !(object instanceof RouterInfo)) return false;
|
||||||
RouterInfo info = (RouterInfo) object;
|
RouterInfo info = (RouterInfo) object;
|
||||||
@ -541,7 +544,8 @@ public class RouterInfo extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(_options, info.getOptions())
|
&& DataHelper.eq(_options, info.getOptions())
|
||||||
&& DataHelper.eq(_peers, info.getPeers());
|
&& DataHelper.eq(_peers, info.getPeers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
if (!_hashCodeInitialized) {
|
if (!_hashCodeInitialized) {
|
||||||
_hashCode = DataHelper.hashCode(_identity) + (int) getPublished();
|
_hashCode = DataHelper.hashCode(_identity) + (int) getPublished();
|
||||||
@ -549,7 +553,8 @@ public class RouterInfo extends DataStructureImpl {
|
|||||||
}
|
}
|
||||||
return _hashCode;
|
return _hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (_stringified != null) return _stringified;
|
if (_stringified != null) return _stringified;
|
||||||
StringBuffer buf = new StringBuffer(5*1024);
|
StringBuffer buf = new StringBuffer(5*1024);
|
||||||
|
@ -57,28 +57,33 @@ public class SessionKey extends DataStructureImpl {
|
|||||||
*/
|
*/
|
||||||
public Object getPreparedKey() { return _preparedKey; }
|
public Object getPreparedKey() { return _preparedKey; }
|
||||||
public void setPreparedKey(Object obj) { _preparedKey = obj; }
|
public void setPreparedKey(Object obj) { _preparedKey = obj; }
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[KEYSIZE_BYTES];
|
_data = new byte[KEYSIZE_BYTES];
|
||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the session key");
|
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the session key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_data == null) throw new DataFormatException("No data in the session key to write out");
|
if (_data == null) throw new DataFormatException("No data in the session key to write out");
|
||||||
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the private key");
|
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the private key");
|
||||||
out.write(_data);
|
out.write(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof SessionKey)) return false;
|
if ((obj == null) || !(obj instanceof SessionKey)) return false;
|
||||||
return DataHelper.eq(_data, ((SessionKey) obj)._data);
|
return DataHelper.eq(_data, ((SessionKey) obj)._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(_data);
|
return DataHelper.hashCode(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (true) return super.toString();
|
if (true) return super.toString();
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
|
@ -35,7 +35,8 @@ public class SessionTag extends ByteArray {
|
|||||||
super();
|
super();
|
||||||
setData(val);
|
setData(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setData(byte val[]) throws IllegalArgumentException {
|
public void setData(byte val[]) throws IllegalArgumentException {
|
||||||
if (val == null)
|
if (val == null)
|
||||||
throw new NullPointerException("SessionTags cannot be null");
|
throw new NullPointerException("SessionTags cannot be null");
|
||||||
|
@ -43,28 +43,33 @@ public class Signature extends DataStructureImpl {
|
|||||||
public void setData(byte[] data) {
|
public void setData(byte[] data) {
|
||||||
_data = data;
|
_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[SIGNATURE_BYTES];
|
_data = new byte[SIGNATURE_BYTES];
|
||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != SIGNATURE_BYTES) throw new DataFormatException("Not enough bytes to read the signature");
|
if (read != SIGNATURE_BYTES) throw new DataFormatException("Not enough bytes to read the signature");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_data == null) throw new DataFormatException("No data in the signature to write out");
|
if (_data == null) throw new DataFormatException("No data in the signature to write out");
|
||||||
if (_data.length != SIGNATURE_BYTES) throw new DataFormatException("Invalid size of data in the private key");
|
if (_data.length != SIGNATURE_BYTES) throw new DataFormatException("Invalid size of data in the private key");
|
||||||
out.write(_data);
|
out.write(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof Signature)) return false;
|
if ((obj == null) || !(obj instanceof Signature)) return false;
|
||||||
return DataHelper.eq(_data, ((Signature) obj)._data);
|
return DataHelper.eq(_data, ((Signature) obj)._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(_data);
|
return DataHelper.hashCode(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[Signature: ");
|
buf.append("[Signature: ");
|
||||||
|
@ -50,27 +50,32 @@ public class SigningPrivateKey extends DataStructureImpl {
|
|||||||
_data = data;
|
_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[KEYSIZE_BYTES];
|
_data = new byte[KEYSIZE_BYTES];
|
||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the private key");
|
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the private key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_data == null) throw new DataFormatException("No data in the private key to write out");
|
if (_data == null) throw new DataFormatException("No data in the private key to write out");
|
||||||
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the private key");
|
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the private key");
|
||||||
out.write(_data);
|
out.write(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof SigningPrivateKey)) return false;
|
if ((obj == null) || !(obj instanceof SigningPrivateKey)) return false;
|
||||||
return DataHelper.eq(_data, ((SigningPrivateKey) obj)._data);
|
return DataHelper.eq(_data, ((SigningPrivateKey) obj)._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(_data);
|
return DataHelper.hashCode(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[SigningPrivateKey: ");
|
buf.append("[SigningPrivateKey: ");
|
||||||
|
@ -49,27 +49,32 @@ public class SigningPublicKey extends DataStructureImpl {
|
|||||||
_data = data;
|
_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[KEYSIZE_BYTES];
|
_data = new byte[KEYSIZE_BYTES];
|
||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the public key");
|
if (read != KEYSIZE_BYTES) throw new DataFormatException("Not enough bytes to read the public key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_data == null) throw new DataFormatException("No data in the public key to write out");
|
if (_data == null) throw new DataFormatException("No data in the public key to write out");
|
||||||
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the public key");
|
if (_data.length != KEYSIZE_BYTES) throw new DataFormatException("Invalid size of data in the public key");
|
||||||
out.write(_data);
|
out.write(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ((obj == null) || !(obj instanceof SigningPublicKey)) return false;
|
if ((obj == null) || !(obj instanceof SigningPublicKey)) return false;
|
||||||
return DataHelper.eq(_data, ((SigningPublicKey) obj)._data);
|
return DataHelper.eq(_data, ((SigningPublicKey) obj)._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DataHelper.hashCode(_data);
|
return DataHelper.hashCode(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(64);
|
StringBuffer buf = new StringBuffer(64);
|
||||||
buf.append("[SigningPublicKey: ");
|
buf.append("[SigningPublicKey: ");
|
||||||
|
@ -68,10 +68,12 @@ public class TunnelId extends DataStructureImpl {
|
|||||||
public int getType() { return _type; }
|
public int getType() { return _type; }
|
||||||
public void setType(int type) { _type = type; }
|
public void setType(int type) { _type = type; }
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_tunnelId = DataHelper.readLong(in, 4);
|
_tunnelId = DataHelper.readLong(in, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||||
if (_tunnelId < 0) throw new DataFormatException("Invalid tunnel ID: " + _tunnelId);
|
if (_tunnelId < 0) throw new DataFormatException("Invalid tunnel ID: " + _tunnelId);
|
||||||
DataHelper.writeLong(out, 4, _tunnelId);
|
DataHelper.writeLong(out, 4, _tunnelId);
|
||||||
@ -82,15 +84,18 @@ public class TunnelId extends DataStructureImpl {
|
|||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if ( (obj == null) || !(obj instanceof TunnelId))
|
if ( (obj == null) || !(obj instanceof TunnelId))
|
||||||
return false;
|
return false;
|
||||||
return getTunnelId() == ((TunnelId)obj).getTunnelId();
|
return getTunnelId() == ((TunnelId)obj).getTunnelId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (int)getTunnelId();
|
return (int)getTunnelId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() { return String.valueOf(getTunnelId()); }
|
public String toString() { return String.valueOf(getTunnelId()); }
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,7 @@ public class VerifiedDestination extends Destination {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(128);
|
StringBuffer buf = new StringBuffer(128);
|
||||||
buf.append(super.toString());
|
buf.append(super.toString());
|
||||||
|
Reference in New Issue
Block a user