[Webfunds-commits] java/webfunds/sox Id.java

Ian Grigg iang@cypherpunks.ai
Sat, 17 Mar 2001 16:18:15 -0400 (AST)


iang        01/03/17 16:18:15

  Modified:    webfunds/sox Id.java
  Log:
  added method to convert printed hash formats back into bytes, so that
  an Id can be then constructed.

Revision  Changes    Path
1.10      +22 -2     java/webfunds/sox/Id.java

Index: Id.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Id.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Id.java	2001/02/27 14:06:23	1.9
+++ Id.java	2001/03/17 20:18:15	1.10
@@ -1,5 +1,5 @@
 /*
- * $Id: Id.java,v 1.9 2001/02/27 14:06:23 iang Exp $
+ * $Id: Id.java,v 1.10 2001/03/17 20:18:15 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -14,7 +14,7 @@
  * an object by means of a hash or similar.
  * This is a pseudo abstract class for other identifier classes.
  *
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
  */
 public /*abstract*/ class Id extends Encodable
     // should be abstract but this makes the test harder
@@ -144,6 +144,26 @@
         if(id == null || id.length == 0)
             return 0 ;                // was: super.hashCode();  why?
         return (id[0]<<24) | (id[1]<<16) | (id[2]<<8) | id[3];
+    }
+
+
+
+////// Convenience ///////////////////////////////////
+
+    /**
+     *  Convert this string representation into the bytes.
+     *  Strips any hint strings that might be present in
+     *  debug outputs, etc.
+     */
+    public static byte[] getBytesFromIdString(String s)
+    {
+        int start = s.indexOf('#');
+        if (start == -1)
+            start = s.indexOf(':');
+        if (start >= 0)
+            s = s.substring(start + 1);
+        byte[] bytes = webfunds.utils.Hex.hex2data(s);
+        return bytes;
     }