Update of /cvsroot/freenet/freenet/src/freenet
In directory sc8-pr-cvs1:/tmp/cvs-serv22801/src/freenet

Modified Files:
        Key.java 
Log Message:
Added capability for Key to convert itself to a BigInteger.

Index: Key.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Key.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- Key.java    30 Oct 2003 01:34:01 -0000      1.7
+++ Key.java    2 Nov 2003 15:35:29 -0000       1.8
@@ -3,6 +3,7 @@
 import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.math.BigInteger;
 import java.util.Hashtable;
 
 import freenet.crypt.ProgressiveHashInputStream;
@@ -34,6 +35,8 @@
     public static final int LOG2_MAXSIZE = 62,
                             LOG2_MINSIZE = 10;
 
+    public static final int KEYBYTES = 23;
+
     private static final Hashtable keytypes = new Hashtable();
 
     /**
@@ -172,6 +175,22 @@
     public Key(byte[] val) {
         this.val = val;
     }
+    
+       // Interpret key as value between 0 and 2^183.
+       public BigInteger toBigInteger() {
+               byte[] b = getVal();
+               if (b.length < KEYBYTES) {
+                       byte[] ob = new byte[KEYBYTES];
+                       System.arraycopy(b, 0, ob, 0, b.length);
+                       b = ob;
+               }
+               if (b.length > KEYBYTES) {
+                       Core.logger.log(this, "Very long key detected!: " + this, new 
Exception("debug"), Logger.NORMAL);
+                       byte[] ob = new byte[KEYBYTES];
+                       System.arraycopy(b, 0, ob, 0, KEYBYTES);
+               }
+               return new BigInteger(1, b);
+       }
 
     /**
      * Makes a copy of the byte array and adds the end bytes

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to