本文整理了Java中net.i2p.data.Hash.<init>()
方法的一些代码示例,展示了Hash.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hash.<init>()
方法的具体详情如下:
包路径:net.i2p.data.Hash
类名称:Hash
方法名:<init>
暂无
代码示例来源:origin: i2p/i2p.i2p
/**
* Extract the hash of the payload of an I2P repliable datagram (previously
* loaded with the loadI2PDatagram() method), without verifying the datagram
* signature.
*
* As of 0.9.14, for signature types other than DSA_SHA1, this returns null.
*
* @return The hash of the payload of the I2P repliable datagram
*/
public Hash extractHash() {
if (rxHash == null)
return null;
// make a copy as we will reuse rxHash
byte[] hash = new byte[Hash.HASH_LENGTH];
System.arraycopy(rxHash, 0, hash, 0, Hash.HASH_LENGTH);
return new Hash(hash);
}
代码示例来源:origin: i2p/i2p.i2p
/** not thread safe */
private HashComparator(Hash h) {
_hash = h;
tmp = new Hash(new byte[Hash.HASH_LENGTH]);
data = new byte[2*Hash.HASH_LENGTH];
System.arraycopy(_hash.getData(), 0, data, Hash.HASH_LENGTH, Hash.HASH_LENGTH);
}
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createStructureToRead() { return new Hash(); }
}
代码示例来源:origin: i2p/i2p.i2p
private static Hash generateRandomKey() {
byte hash[] = new byte[Hash.HASH_LENGTH];
RandomSource.getInstance().nextBytes(hash);
return new Hash(hash);
}
代码示例来源:origin: i2p/i2p.i2p
/**
* Calculate the HMAC of the data with the given key
*
* @return the first 16 bytes contain the HMAC, the last 16 bytes are zero
* @deprecated unused (not even by Syndie)
*/
@Deprecated
public Hash calculate(SessionKey key, byte data[]) {
if ((key == null) || (key.getData() == null) || (data == null))
throw new NullPointerException("Null arguments for HMAC");
byte rv[] = acquireTmp();
Arrays.fill(rv, (byte)0x0);
calculate(key, data, 0, data.length, rv, 0);
return new Hash(rv);
}
代码示例来源:origin: i2p/i2p.i2p
/**
* Announce somebody else we know about to ourselves.
* Non-blocking.
*
* @param ih the Info Hash (torrent)
* @param peerHash the peer's Hash
*/
public void announce(byte[] ih, byte[] peerHash, boolean isSeed) {
InfoHash iHash = new InfoHash(ih);
_tracker.announce(iHash, new Hash(peerHash), isSeed);
// Do NOT do this, corrupts the Hash cache and the Peer ID
//_tracker.announce(iHash, Hash.create(peerHash));
}
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createDataStructure() throws DataFormatException {
Hash hash = new Hash();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
hash.setData(data);
return hash;
}
public DataStructure createStructureToRead() { return new Hash(); }
代码示例来源:origin: i2p/i2p.i2p
private void addFromProperties() {
for (String prop : _ctx.getPropertyNames()) {
if (!prop.startsWith(PROP_PFX))
continue;
String key = _ctx.getProperty(prop);
if (key == null || key.length() != 44)
continue;
String hb = prop.substring(PROP_PFX.length());
hb = hb.replace("$", "=");
Hash dest = new Hash();
SessionKey sk = new SessionKey();
try {
dest.fromBase64(hb);
sk.fromBase64(key);
super.put(dest, sk);
} catch (DataFormatException dfe) { continue; }
}
}
}
代码示例来源:origin: i2p/i2p.i2p
/**
* @since 0.9.9
* @throws UnsupportedOperationException if not supported
*/
public SimpleDataStructure getHashInstance() {
switch (getHashLen()) {
case 20:
return new SHA1Hash();
case 32:
return new Hash();
case 48:
return new Hash384();
case 64:
return new Hash512();
default:
throw new UnsupportedOperationException("Unsupported hash length: " + getHashLen());
}
}
代码示例来源:origin: i2p/i2p.i2p
/** @since 0.9.10 */
public void testClosest() {
byte val[] = new byte[Hash.HASH_LENGTH];
for (int i = 0; i < 23; i++) {
context.random().nextBytes(val);
Hash h = new Hash(val);
List<Hash> c = set.getClosest(h, i);
assertTrue(c.size() == i);
}
}
}
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createDataStructure() throws DataFormatException {
byte h[] = new byte[Hash.HASH_LENGTH];
RandomSource.getInstance().nextBytes(h);
Hash hash = new Hash(h);
DestLookupMessage msg = new DestLookupMessage(hash);
return msg;
}
public DataStructure createStructureToRead() { return new DestLookupMessage(); }
代码示例来源:origin: i2p/i2p.i2p
@Test
public void testRouter() throws Exception {
int runCount = 1;
List<DataMessage> messages = new ArrayList<DataMessage>(runCount);
long start = _context.clock().now();
for (int i = 0; i < runCount; i++) {
DataMessage m = getTestMessage(64);
Hash to = new Hash(new byte[Hash.HASH_LENGTH]);
java.util.Arrays.fill(to.getData(), (byte)0xFF);
messages.add(m);
_gw.add(m, to, null);
}
Thread.sleep(1000);
List<I2NPMessage> received = _receiver.clearReceived();
for (int i = 0; i < messages.size(); i++) {
assertTrue(received.contains(((I2NPMessage)messages.get(i))));
}
}
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createDataStructure() throws DataFormatException {
Lease lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
StructureTest tst = new TunnelIdTest();
lease.setTunnelId((TunnelId)tst.createDataStructure());
return lease;
}
public DataStructure createStructureToRead() { return new Lease(); }
代码示例来源:origin: i2p/i2p.i2p
@Test
public void failsWriteWithNullTunnelId() throws Exception{
Lease lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
lease.setTunnelId(null);
exception.expect(DataFormatException.class);
exception.expectMessage("Not enough data to write out a Lease");
lease.writeBytes(new ByteArrayOutputStream());
}
代码示例来源:origin: i2p/i2p.i2p
@Test
public void testNullEquals() throws Exception{
Lease lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
lease.setTunnelId(null);
assertFalse(lease.equals(null));
}
}
代码示例来源:origin: i2p/i2p.i2p
private void addRandom(int count) {
for (int i = 0; i < count; i++) {
byte val[] = new byte[Hash.HASH_LENGTH];
context.random().nextBytes(val);
Hash h = new Hash(val);
// in the highly unlikely chance we randomly generate a hash equal to us
assertTrue(set.add(h) || h.equals(usHash));
}
}
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createDataStructure() throws DataFormatException {
RequestLeaseSetMessage msg = new RequestLeaseSetMessage();
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
msg.setEndDate(new Date(1000*60*60*12));
byte h[] = new byte[Hash.HASH_LENGTH];
msg.addEndpoint(new Hash(h), (TunnelId)(new TunnelIdTest()).createDataStructure());
return msg;
}
public DataStructure createStructureToRead() { return new RequestLeaseSetMessage(); }
代码示例来源:origin: i2p/i2p.i2p
public void setUp(){
context = I2PAppContext.getGlobalContext();
log = context.logManager().getLog(KBucketSet.class);
byte[] us = new byte[Hash.HASH_LENGTH];
context.random().nextBytes(us);
usHash = new Hash(us);
// We use the default RandomTrimmer so add() will never fail
set = new KBucketSet<Hash>(context, usHash, K, B);
// tests may be run in any order so prime it
addRandom(1000);
}
代码示例来源:origin: i2p/i2p.i2p
@Test
public void testExpiration() throws Exception{
Lease lease = new Lease();
assertTrue(lease.isExpired());
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
StructureTest tst = new TunnelIdTest();
lease.setTunnelId((TunnelId)tst.createDataStructure());
assertTrue(lease.isExpired());
}
代码示例来源:origin: i2p/i2p.i2p
protected PendingGatewayMessage createPending(int size, boolean includeRouter, boolean includeTunnel) {
DataMessage m = new DataMessage(_context);
byte data[] = new byte[size];
_context.random().nextBytes(data);
m.setData(data);
m.setUniqueId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
m.setMessageExpiration(_context.clock().now() + 60*1000);
Hash toRouter = null;
TunnelId toTunnel = null;
if (includeRouter) {
toRouter = new Hash(new byte[Hash.HASH_LENGTH]);
_context.random().nextBytes(toRouter.getData());
}
if (includeTunnel)
toTunnel = new TunnelId(1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE));
return new PendingGatewayMessage(m, toRouter, toTunnel);
}
内容来源于网络,如有侵权,请联系作者删除!