@Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append('[').append(getClass().getSimpleName()).append(": "); int length = length(); if (_data == null) { buf.append("null"); } else if (length <= 32) { buf.append(toBase64()); } else { buf.append("size: ").append(Integer.toString(length)); } buf.append(']'); return buf.toString(); }
/** * @param target key to compare distances with */ public XORComparator(T target) { _base = target.getData(); }
/** * Sets the data. * @param in the stream to read * @throws RuntimeException if data already set. */ public void readBytes(InputStream in) throws DataFormatException, IOException { if (_data != null) throw new RuntimeException("Data already set"); int length = length(); _data = new byte[length]; // Throws on incomplete read read(in, _data); }
/** * Sets the data. * @param data 32 bytes, or null * @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok) * @throws RuntimeException if data already set. */ @Override public void setData(byte[] data) { super.setData(data); }
/** * Overridden for efficiency. * Does the same thing as setData() but null not allowed. * @param data non-null * @throws DataFormatException if null or wrong length * @throws RuntimeException if data already set. */ @Override public void fromByteArray(byte data[]) throws DataFormatException { if (data == null) throw new DataFormatException("Null data passed in"); if (data.length != length()) throw new DataFormatException("Bad data length: " + data.length + "; required: " + length()); // call setData() instead of _data = data in case overridden setData(data); }
/** * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 * @param h hash of secret data, same length as this key * @throws UnsupportedOperationException unless supported */ public static SigningPublicKey blind(SigningPublicKey key, SimpleDataStructure h) { if (key.getType() != TYPE) throw new UnsupportedOperationException(); if (h.length() != key.length()) throw new IllegalArgumentException(); try { EdDSAPublicKey jk = SigUtil.toJavaEdDSAKey(key); EdDSAPublicKey bjk = EdDSABlinding.blind(jk, h.getData()); return SigUtil.fromJavaKey(bjk, TYPE); } catch (GeneralSecurityException gse) { throw new IllegalArgumentException(gse); } }
/** * @since 0.9.17 */ @Override public int hashCode() { return DataHelper.hashCode(_type) ^ super.hashCode(); }
@Override public String toBase64() { if (_base64ed == null) { _base64ed = super.toBase64(); } return _base64ed; }
SimpleDataStructure[] keys = _context.keyGenerator().generateSigningKeys(type); pub.writeBytes(keyStream); keys[0].writeBytes(keyStream); // signing pub Certificate.NULL_CERT.writeBytes(keyStream); priv.writeBytes(keyStream); keys[1].writeBytes(keyStream); // signing priv } catch (GeneralSecurityException e) { throw new I2PSessionException("Error creating keys", e);
/** * Sets the data. * @param data of correct length, or null * @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok) * @throws RuntimeException if data already set. */ public void setData(byte[] data) { if (_data != null) throw new RuntimeException("Data already set"); if (data != null && data.length != length()) throw new IllegalArgumentException("Bad data length: " + data.length + "; required: " + length()); _data = data; }
@Override public void readBytes(InputStream in) throws DataFormatException, IOException { super.readBytes(in); _cachedHashCode = SipHash.hashCode(_data); }
@Override public String toString() { StringBuilder buf = new StringBuilder(1024); buf.append("<div class=\"debug_container buckets\">"); buf.append("<hr><b>Bucket set rooted on:</b> ").append(_us.toString()) .append(" K=").append(BUCKET_SIZE) .append(" B=").append(B_VALUE) .append(" with ").append(size()) .append(" keys in ").append(_buckets.size()).append(" buckets:<br>\n"); getReadLock(); try { int len = _buckets.size(); for (int i = 0; i < len; i++) { KBucket<T> b = _buckets.get(i); buf.append("<b>Bucket ").append(i).append("/").append(len).append(":</b> "); buf.append(b.toString()).append("<br>\n"); } } finally { releaseReadLock(); } buf.append("</div>"); return buf.toString(); } }
if (key.equals(_us)) return getClosest(max, toIgnore); List<T> rv = new ArrayList<T>(max);
/** @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok) */ public SimpleDataStructure(byte data[]) { setData(data); }
/** * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 * @param h hash of secret data, same length as this key * @throws UnsupportedOperationException unless supported */ public static SigningPrivateKey blind(SigningPrivateKey key, SimpleDataStructure h) { if (key.getType() != TYPE) throw new UnsupportedOperationException(); if (h.length() != key.length()) throw new IllegalArgumentException(); try { EdDSAPrivateKey jk = SigUtil.toJavaEdDSAKey(key); EdDSAPrivateKey bjk = EdDSABlinding.blind(jk, h.getData()); return SigUtil.fromJavaKey(bjk, TYPE); } catch (GeneralSecurityException gse) { throw new IllegalArgumentException(gse); } }
/** * @since 0.9.17 */ @Override public int hashCode() { return DataHelper.hashCode(_type) ^ super.hashCode(); }