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

Ian Grigg iang@cypherpunks.ai
Tue, 20 Mar 2001 19:15:46 -0400 (AST)


iang        01/03/20 19:15:46

  Modified:    webfunds/sox Utils.java
  Log:
  added example for BigIntegers

Revision  Changes    Path
1.22      +22 -1     java/webfunds/sox/Utils.java

Index: Utils.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Utils.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Utils.java	2001/03/18 23:20:56	1.21
+++ Utils.java	2001/03/20 23:15:46	1.22
@@ -1,5 +1,5 @@
 /*
- * $Id: Utils.java,v 1.21 2001/03/18 23:20:56 iang Exp $
+ * $Id: Utils.java,v 1.22 2001/03/20 23:15:46 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -7,6 +7,7 @@
 package webfunds.sox;
 
 import java.io.*;
+import java.math.BigInteger;
 import java.security.*;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
@@ -192,5 +193,25 @@
 
     public static PrivateKey examplePrivateKey() {
          throw new RuntimeException("No crypto here!");
+    }
+
+    /**
+     *  @param len bytes, where len >= 1
+     */
+    public static BigInteger examplePosBigInt(int len)
+    {
+        byte[] data = exampleData(len);
+        data[0] &= 0x7F;                     // so always positive
+        return new BigInteger(data);
+    }
+
+    /**
+     *  @return something from 8 bytes to 16 bytes worth of big int.
+     */
+    public static BigInteger examplePosBigInt()
+    {
+        int len = exampleByte() & 0x07;
+        len |= 0x08;
+        return examplePosBigInt(len);
     }
 }