Author: toad
Date: 2008-07-04 00:08:50 +0000 (Fri, 04 Jul 2008)
New Revision: 20959
Modified:
branches/db4o/freenet/src/freenet/keys/Key.java
branches/db4o/freenet/src/freenet/keys/NodeCHK.java
branches/db4o/freenet/src/freenet/keys/NodeSSK.java
Log:
cloneKey()
Modified: branches/db4o/freenet/src/freenet/keys/Key.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/Key.java 2008-07-04 00:07:53 UTC
(rev 20958)
+++ branches/db4o/freenet/src/freenet/keys/Key.java 2008-07-04 00:08:50 UTC
(rev 20959)
@@ -45,6 +45,15 @@
cachedNormalizedDouble = -1;
}
+ protected Key(Key key) {
+ this.hash = key.hash;
+ this.cachedNormalizedDouble = key.cachedNormalizedDouble;
+ this.routingKey = new byte[key.routingKey.length];
+ System.arraycopy(key.routingKey, 0, routingKey, 0, routingKey.length);
+ }
+
+ public abstract Key cloneKey();
+
/**
* Write to disk.
* Take up exactly 22 bytes.
Modified: branches/db4o/freenet/src/freenet/keys/NodeCHK.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/NodeCHK.java 2008-07-04 00:07:53 UTC
(rev 20958)
+++ branches/db4o/freenet/src/freenet/keys/NodeCHK.java 2008-07-04 00:08:50 UTC
(rev 20959)
@@ -28,6 +28,15 @@
throw new IllegalArgumentException("Wrong length:
"+routingKey2.length+" should be "+KEY_LENGTH);
this.cryptoAlgorithm = cryptoAlgorithm;
}
+
+ private NodeCHK(NodeCHK key) {
+ super(key);
+ this.cryptoAlgorithm = key.cryptoAlgorithm;
+ }
+
+ public Key cloneKey() {
+ return new NodeCHK(this);
+ }
public static final int KEY_LENGTH = 32;
@@ -58,6 +67,7 @@
}
public boolean equals(Object key) {
+ if(key == this) return true;
if(key instanceof NodeCHK) {
NodeCHK chk = (NodeCHK) key;
return java.util.Arrays.equals(chk.routingKey, routingKey) &&
(cryptoAlgorithm == chk.cryptoAlgorithm);
Modified: branches/db4o/freenet/src/freenet/keys/NodeSSK.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/NodeSSK.java 2008-07-04 00:07:53 UTC
(rev 20958)
+++ branches/db4o/freenet/src/freenet/keys/NodeSSK.java 2008-07-04 00:08:50 UTC
(rev 20959)
@@ -68,6 +68,21 @@
hashCode = Fields.hashCode(pkHash) ^ Fields.hashCode(ehDocname);
}
+ private NodeSSK(NodeSSK key) {
+ super(key);
+ this.cryptoAlgorithm = key.cryptoAlgorithm;
+ this.pubKey = key.pubKey;
+ this.pubKeyHash = new byte[key.pubKeyHash.length];
+ System.arraycopy(key.pubKeyHash, 0, pubKeyHash, 0,
key.pubKeyHash.length);
+ this.encryptedHashedDocname = new
byte[key.encryptedHashedDocname.length];
+ System.arraycopy(key.encryptedHashedDocname, 0, encryptedHashedDocname,
0, key.encryptedHashedDocname.length);
+ this.hashCode = key.hashCode;
+ }
+
+ public Key cloneKey() {
+ return new NodeSSK(this);
+ }
+
// routingKey = H( E(H(docname)) + H(pubkey) )
private static byte[] makeRoutingKey(byte[] pkHash, byte[] ehDocname) {
MessageDigest md256 = SHA256.getMessageDigest();
@@ -147,6 +162,7 @@
}
public boolean equals(Object o) {
+ if(o == this) return true;
if(!(o instanceof NodeSSK)) return false;
NodeSSK key = (NodeSSK)o;
if(!Arrays.equals(key.encryptedHashedDocname,
encryptedHashedDocname)) return false;