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

Ian Grigg iang@cypherpunks.ai
Tue, 5 Dec 2000 13:38:30 -0400 (AST)


iang        00/12/05 13:38:30

  Modified:    webfunds/sox PaymentFactory.java
  Log:
  1. Added search for payment type from a string.
  2. Added factory method to create a key suitable for specified token type.

Revision  Changes    Path
1.7       +52 -1     java/webfunds/sox/PaymentFactory.java

Index: PaymentFactory.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/PaymentFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PaymentFactory.java	2000/11/30 13:40:09	1.6
+++ PaymentFactory.java	2000/12/05 17:38:29	1.7
@@ -1,10 +1,11 @@
-/* $Id: PaymentFactory.java,v 1.6 2000/11/30 13:40:09 iang Exp $
+/* $Id: PaymentFactory.java,v 1.7 2000/12/05 17:38:29 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team. All Rights Reserved.
  */
 package webfunds.sox;
 
+import java.security.KeyPair;
 
 public final class PaymentFactory
 {
@@ -102,6 +103,56 @@
             return "<" + type + " invalid>";
         }
         return typeNames[type] + " (" + type + ")";
+    }
+
+    /**
+     *  Return a the type number for this payment name.
+     *  Meant for converting user-land strings to the number.
+     *
+     *  @return the type number constant or NONE, if unknown
+     */
+    public static int getType(String name)
+    {
+        if (name == null || name.length() < 0)
+            return NONE;
+
+        for (int i = 0; i < base64Type.length; i++)
+        {
+            if (name.equals(base64Type[i]))
+                return i;
+        }
+
+        for (int i = 0; i < typeNames.length; i++)
+        {
+            if (name.equals(typeNames[i]))
+                return i;
+        }
+
+        return NONE;
+    }
+
+    /**
+     *  Get me a KeyPair for some token series.
+     */
+    public static KeyPair createKeyPair(int typ, byte[] series, int log)
+        throws SOXKeyException
+    {
+        
+        if (!valid(typ) || (series == null) || (log < 0))
+            throw new IllegalArgumentException("PF.createKeyPair(?)");
+
+        KeyPair kp;
+
+        if (typ == RANDOM_TOKEN)
+            kp = RandomToken.createKeyPair(series, log);
+        /*
+        else if (typ == WAGNER_TOKEN)
+            kp = WagnerToken.createKeyPair(series, log);
+        */
+        else
+            throw new IllegalArgumentException("createKeyPair("+typ+")");
+
+        return kp;
     }