Author: toad
Date: 2008-07-18 21:14:23 +0000 (Fri, 18 Jul 2008)
New Revision: 21218
Modified:
branches/db4o/freenet/src/freenet/crypt/DSAGroup.java
branches/db4o/freenet/src/freenet/crypt/DSAPublicKey.java
Log:
Add cloneKey()
Modified: branches/db4o/freenet/src/freenet/crypt/DSAGroup.java
===================================================================
--- branches/db4o/freenet/src/freenet/crypt/DSAGroup.java 2008-07-18
21:12:20 UTC (rev 21217)
+++ branches/db4o/freenet/src/freenet/crypt/DSAGroup.java 2008-07-18
21:14:23 UTC (rev 21218)
@@ -64,7 +64,13 @@
throw new IllegalArgumentException();
}
- /**
+ private DSAGroup(DSAGroup group) {
+ this.p = new NativeBigInteger(1, group.p.toByteArray());
+ this.q = new NativeBigInteger(1, group.q.toByteArray());
+ this.g = new NativeBigInteger(1, group.g.toByteArray());
+ }
+
+ /**
* Parses a DSA Group from a string, where p, q, and g are in unsigned
* hex-strings, separated by a commas
*/
@@ -238,4 +244,9 @@
return "Global.DSAgroupBigA";
return "p="+HexUtil.biToHex(p)+", q="+HexUtil.biToHex(q)+",
g="+HexUtil.biToHex(g);
}
+
+ public DSAGroup cloneKey() {
+ if(this == Global.DSAgroupBigA) return this;
+ return new DSAGroup(this);
+ }
}
Modified: branches/db4o/freenet/src/freenet/crypt/DSAPublicKey.java
===================================================================
--- branches/db4o/freenet/src/freenet/crypt/DSAPublicKey.java 2008-07-18
21:12:20 UTC (rev 21217)
+++ branches/db4o/freenet/src/freenet/crypt/DSAPublicKey.java 2008-07-18
21:14:23 UTC (rev 21218)
@@ -59,6 +59,12 @@
this(new ByteArrayInputStream(pubkeyBytes));
}
+ private DSAPublicKey(DSAPublicKey key) {
+ fingerprint = null; // regen when needed
+ this.y = new NativeBigInteger(1, key.y.toByteArray());
+ this.group = key.group.cloneKey();
+ }
+
public static DSAPublicKey create(byte[] pubkeyAsBytes) throws
CryptFormatException {
try {
return new DSAPublicKey(new
ByteArrayInputStream(pubkeyAsBytes));
@@ -201,4 +207,8 @@
public byte[] getRoutingKey() {
return asBytesHash();
}
+
+ public DSAPublicKey cloneKey() {
+ return new DSAPublicKey(this);
+ }
}