forked from I2P_Developers/i2p.i2p
Util: Move fromLong8()/toLong8() methods to DataHelper
This commit is contained in:
@ -808,6 +808,37 @@ public class DataHelper {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Big endian.
|
||||
* Same as fromLong(src, offset, 8) but allows negative result
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
* @since 0.9.47 moved from NTCP2Payload
|
||||
*/
|
||||
public static long fromLong8(byte src[], int offset) {
|
||||
long rv = 0;
|
||||
int limit = offset + 8;
|
||||
for (int i = offset; i < limit; i++) {
|
||||
rv <<= 8;
|
||||
rv |= src[i] & 0xFF;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Big endian.
|
||||
* Same as toLong(target, offset, 8, value) but allows negative value
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
* @since 0.9.47 moved from NTCP2Payload
|
||||
*/
|
||||
public static void toLong8(byte target[], int offset, long value) {
|
||||
for (int i = offset + 7; i >= offset; i--) {
|
||||
target[i] = (byte) value;
|
||||
value >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/** Read in a date from the stream as specified by the I2P data structure spec.
|
||||
* A date is an 8 byte unsigned integer in network byte order specifying the number of
|
||||
* milliseconds since midnight on January 1, 1970 in the GMT timezone. If the number is
|
||||
|
@ -474,35 +474,6 @@ class RatchetPayload {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Big endian.
|
||||
* Same as DataHelper.fromLong(src, offset, 8) but allows negative result
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
static long fromLong8(byte src[], int offset) {
|
||||
long rv = 0;
|
||||
int limit = offset + 8;
|
||||
for (int i = offset; i < limit; i++) {
|
||||
rv <<= 8;
|
||||
rv |= src[i] & 0xFF;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Big endian.
|
||||
* Same as DataHelper.toLong(target, offset, 8, value) but allows negative value
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
static void toLong8(byte target[], int offset, long value) {
|
||||
for (int i = offset + 7; i >= offset; i--) {
|
||||
target[i] = (byte) value;
|
||||
value >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Big endian.
|
||||
* Same as DataHelper.toLong(target, offset, 4, value) but allows negative value
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.i2p.router.crypto.ratchet;
|
||||
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
/**
|
||||
* 8 bytes of random data.
|
||||
@ -23,7 +24,7 @@ public class RatchetSessionTag {
|
||||
public RatchetSessionTag(byte val[]) {
|
||||
if (val.length < LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
_data = RatchetPayload.fromLong8(val, 0);
|
||||
_data = DataHelper.fromLong8(val, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,7 +32,7 @@ public class RatchetSessionTag {
|
||||
*/
|
||||
public byte[] getData() {
|
||||
byte[] rv = new byte[LENGTH];
|
||||
RatchetPayload.toLong8(rv, 0, _data);
|
||||
DataHelper.toLong8(rv, 0, _data);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ class NTCP2Payload {
|
||||
throw new IOException("Illegal block in handshake: " + type);
|
||||
if (len < 9)
|
||||
throw new IOException("Bad length for TERMINATION: " + len);
|
||||
long last = fromLong8(payload, i);
|
||||
long last = DataHelper.fromLong8(payload, i);
|
||||
int rsn = payload[i + 8] & 0xff;
|
||||
cb.gotTermination(rsn, last);
|
||||
gotTermination = true;
|
||||
@ -333,40 +333,9 @@ class NTCP2Payload {
|
||||
}
|
||||
|
||||
public int writeData(byte[] tgt, int off) {
|
||||
toLong8(tgt, off, rcvd);
|
||||
DataHelper.toLong8(tgt, off, rcvd);
|
||||
tgt[off + 8] = rsn;
|
||||
return off + 9;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Big endian.
|
||||
* Same as DataHelper.fromLong(src, offset, 8) but allows negative result
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
* @since 0.9.36
|
||||
*/
|
||||
private static long fromLong8(byte src[], int offset) {
|
||||
long rv = 0;
|
||||
int limit = offset + 8;
|
||||
for (int i = offset; i < limit; i++) {
|
||||
rv <<= 8;
|
||||
rv |= src[i] & 0xFF;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Big endian.
|
||||
* Same as DataHelper.toLong(target, offset, 8, value) but allows negative value
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
* @since 0.9.36
|
||||
*/
|
||||
private static void toLong8(byte target[], int offset, long value) {
|
||||
for (int i = offset + 7; i >= offset; i--) {
|
||||
target[i] = (byte) value;
|
||||
value >>= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user