[freenet-cvs] r11725 - trunk/freenet/src/freenet/crypt

toad at freenetproject.org toad at freenetproject.org
Fri Feb 9 23:39:05 UTC 2007


Author: toad
Date: 2007-02-09 23:39:04 +0000 (Fri, 09 Feb 2007)
New Revision: 11725

Modified:
   trunk/freenet/src/freenet/crypt/CryptoElement.java
   trunk/freenet/src/freenet/crypt/DHGroup.java
   trunk/freenet/src/freenet/crypt/DSAGroup.java
   trunk/freenet/src/freenet/crypt/DSAPrivateKey.java
   trunk/freenet/src/freenet/crypt/DSAPublicKey.java
   trunk/freenet/src/freenet/crypt/DSASignature.java
Log:
Don't cache hex versions of DSA parameters.
writeAsField -> toLongString

Modified: trunk/freenet/src/freenet/crypt/CryptoElement.java
===================================================================
--- trunk/freenet/src/freenet/crypt/CryptoElement.java	2007-02-09 23:24:41 UTC (rev 11724)
+++ trunk/freenet/src/freenet/crypt/CryptoElement.java	2007-02-09 23:39:04 UTC (rev 11725)
@@ -12,8 +12,8 @@
 
     //public void write(OutputStream o) throws IOException;
 
-    public String writeAsField();
+    //public String writeAsField();
 
+	public String toLongString();
 
-
 }

Modified: trunk/freenet/src/freenet/crypt/DHGroup.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DHGroup.java	2007-02-09 23:24:41 UTC (rev 11724)
+++ trunk/freenet/src/freenet/crypt/DHGroup.java	2007-02-09 23:39:04 UTC (rev 11725)
@@ -27,7 +27,7 @@
 //		super.write(out, getClass().getName());
 //	}
 //
-	public String writeAsField() {
+	public String toLongString() {
 		String pStr = HexUtil.biToHex(p);
 		String gStr = HexUtil.biToHex(g);
 		StringBuffer b = new StringBuffer(pStr.length() + gStr.length() + 1);

Modified: trunk/freenet/src/freenet/crypt/DSAGroup.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSAGroup.java	2007-02-09 23:24:41 UTC (rev 11724)
+++ trunk/freenet/src/freenet/crypt/DSAGroup.java	2007-02-09 23:39:04 UTC (rev 11725)
@@ -27,8 +27,6 @@
 
     private final BigInteger p, q, g;
 
-    private String pAsHexString, gAsHexString, qAsHexString; //Cached versions
-
     // of the
     // hexadecimal
     // string
@@ -45,10 +43,6 @@
 
     public DSAGroup(String pAsHexString, String qAsHexString,
             String gAsHexString) throws NumberFormatException {
-        this.pAsHexString = pAsHexString;
-        this.qAsHexString = qAsHexString;
-        this.gAsHexString = gAsHexString;
-
         //Sanity check. Needed because of the Kaffe workaround further down
         if ((pAsHexString == null) || (qAsHexString == null)
                 || (gAsHexString == null))
@@ -69,14 +63,6 @@
         	throw new IllegalArgumentException();
     }
 
-    private void updateCachedHexStrings() {
-    	if(pAsHexString != null && qAsHexString != null && gAsHexString != null)
-    		return;
-        pAsHexString = HexUtil.biToHex(p);
-        qAsHexString = HexUtil.biToHex(q);
-        gAsHexString = HexUtil.biToHex(g);
-    }
-
     /**
      * Parses a DSA Group from a string, where p, q, and g are in unsigned
      * hex-strings, separated by a commas
@@ -109,15 +95,6 @@
     //		writeForWire(out);
     //    }
 
-    public String writeAsField() {
-    	updateCachedHexStrings();
-        StringBuffer b = new StringBuffer();
-        b.append(pAsHexString).append(',');
-        b.append(qAsHexString).append(',');
-        b.append(gAsHexString);
-        return b.toString();
-    }
-
     public String keyType() {
         return "DSA.g-" + p.bitLength();
     }
@@ -134,21 +111,6 @@
         return g;
     }
 
-    public String getPAsHexString() {
-    	updateCachedHexStrings();
-        return pAsHexString;
-    }
-
-    public String getQAsHexString() {
-    	updateCachedHexStrings();
-        return qAsHexString;
-    }
-
-    public String getGAsHexString() {
-    	updateCachedHexStrings();
-        return gAsHexString;
-    }
-
     public byte[] fingerprint() {
         BigInteger fp[] = new BigInteger[3];
         fp[0] = p;
@@ -341,4 +303,16 @@
 		if(dg.equals(Global.DSAgroupBigA)) return Global.DSAgroupBigA;
 		return dg;
 	}
+	
+	public String toString() {
+		if(this == Global.DSAgroupBigA)
+			return "Global.DSAgroupBigA";
+		else return super.toString();
+	}
+	
+	public String toLongString() {
+		if(this == Global.DSAgroupBigA)
+			return "Global.DSAgroupBigA";
+		return "p="+HexUtil.biToHex(p)+", q="+HexUtil.biToHex(q)+", g="+HexUtil.biToHex(g);
+	}
 }

Modified: trunk/freenet/src/freenet/crypt/DSAPrivateKey.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSAPrivateKey.java	2007-02-09 23:24:41 UTC (rev 11724)
+++ trunk/freenet/src/freenet/crypt/DSAPrivateKey.java	2007-02-09 23:39:04 UTC (rev 11725)
@@ -51,8 +51,8 @@
         return new DSAPrivateKey(Util.readMPI(i));
     }
     
-    public String writeAsField() {
-        return HexUtil.biToHex(x);
+    public String toLongString() {
+        return "x="+HexUtil.biToHex(x);
     }
     
     // what?  why is DSAGroup passed in?

Modified: trunk/freenet/src/freenet/crypt/DSAPublicKey.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSAPublicKey.java	2007-02-09 23:24:41 UTC (rev 11724)
+++ trunk/freenet/src/freenet/crypt/DSAPublicKey.java	2007-02-09 23:39:04 UTC (rev 11725)
@@ -16,8 +16,6 @@
 	private static final long serialVersionUID = -1;
     
     private final BigInteger y;
-	/** A cache of the hexadecimal string representation of y */
-    private String yAsHexString; 
     
     public static final int PADDED_SIZE = 1024;
 
@@ -39,7 +37,6 @@
 	public DSAPublicKey(DSAGroup g, String yAsHexString) throws NumberFormatException {
 		this.y=new NativeBigInteger(yAsHexString,16);
     	if(y.signum() != 1) throw new IllegalArgumentException();
-		this.yAsHexString = yAsHexString;
 		this.group=g;
 		if(g == null) throw new NullPointerException();
 	}
@@ -61,36 +58,18 @@
 		return y;
     }
     
-	public String getYAsHexString() {
-		if(yAsHexString == null)
-			this.yAsHexString = HexUtil.biToHex(y);
-		return yAsHexString;
-	}
-
     public BigInteger getP() {
 		return group.getP();
     }
     
-	public String getPAsHexString() {
-		return group.getPAsHexString();
-	}
-    
     public BigInteger getQ() {
 		return group.getQ();
     }
     
-	public String getQAsHexString() {
-		return group.getQAsHexString();
-	}
-
     public BigInteger getG() {
 		return group.getG();
     }
     
-	public String getGAsHexString() {
-		return group.getGAsHexString();
-	}
-
     public String keyType() {
 		return "DSA.p";
     }
@@ -123,8 +102,8 @@
 		return y.intValue();
     }
 
-    public String writeAsField() {
-        return yAsHexString;
+    public String toLongString() {
+        return "y="+HexUtil.biToHex(y);
     }
 
     // this won't correctly read the output from writeAsField

Modified: trunk/freenet/src/freenet/crypt/DSASignature.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSASignature.java	2007-02-09 23:24:41 UTC (rev 11724)
+++ trunk/freenet/src/freenet/crypt/DSASignature.java	2007-02-09 23:39:04 UTC (rev 11725)
@@ -48,13 +48,6 @@
 		Util.writeMPI(s, o);
     }
 
-    /** @deprecated
-      * @see #toString()
-      */
-    public String writeAsField() {
-        return toString();
-    }
-    
     public DSASignature(BigInteger r, BigInteger s) {
 		this.r=r;
 		this.s=s;
@@ -71,7 +64,7 @@
 		return s;
     }
 
-    public String toString() {
+    public String toLongString() {
 		if(toStringCached == null)
 			toStringCached = HexUtil.biToHex(r) + ',' + HexUtil.biToHex(s);
         return toStringCached;




More information about the cvs mailing list