[Webfunds-commits] java/webfunds/sox Account.java ItemId.java

Ian Grigg iang@cypherpunks.ai
Sun, 18 Mar 2001 19:23:13 -0400 (AST)


iang        01/03/18 19:23:13

  Modified:    webfunds/client/sox SOXWallet.java
               webfunds/ricardian Contract.java
               webfunds/sox Account.java ItemId.java
  Log:
  rewrote to cope with new Armoury and Payment methods.

Revision  Changes    Path
1.146     +72 -101   java/webfunds/client/sox/SOXWallet.java

Index: SOXWallet.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/SOXWallet.java,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -r1.145 -r1.146
--- SOXWallet.java	2001/03/18 03:21:07	1.145
+++ SOXWallet.java	2001/03/18 23:23:11	1.146
@@ -1,4 +1,4 @@
-/* $Id: SOXWallet.java,v 1.145 2001/03/18 03:21:07 iang Exp $
+/* $Id: SOXWallet.java,v 1.146 2001/03/18 23:23:11 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -30,7 +30,7 @@
 
 import webfunds.sox.Account;
 import webfunds.sox.AccountId;
-import webfunds.sox.Armoury;
+import webfunds.sox.ArmouredPayment;
 import webfunds.sox.Crypto;
 import webfunds.sox.IssuerFinder;
 import webfunds.sox.ItemId;
@@ -77,7 +77,7 @@
  *  See quiteCancel for example of low call.  It should not use AccountInfo
  *  (artifact of Receipt Store).
  *
- * @version $Revision: 1.145 $
+ * @version $Revision: 1.146 $
  */
 public class SOXWallet
     extends Debug
@@ -1171,7 +1171,8 @@
     public final static String SOX_MESSAGE = "SOX MESSAGE";
 
     /**
-     *  Make an ASCII-armoured message from a payment, a la PGP armouring.
+     *  Make an ASCII-armoured message from a payment,
+     *  a la PGP armouring.  Filters out exceptions.
      *  Low level wallet.
      */
     public byte[] asciiArmour(AbstractPayment pay)
@@ -1179,18 +1180,20 @@
     {
         if (pay == null)
             throw new PaymentException("null");
+
+        ArmouredPayment ap = new ArmouredPayment(pay);
+        return ap.encode();
 
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+/*
+        byte[] buf;
         try {
-            pay.encode(bos);
+            buf = ap.encode();
         } catch (IOException ex) {
-            ex.printStackTrace();
             throw new PaymentException("Payment no good: " + ex);
         }
 
-        String s = Armoury.encode(SOX_MESSAGE, bos.toByteArray());
-
-        return s.getBytes();
+        return buf;
+*/
     }
 
     /**
@@ -1199,51 +1202,62 @@
      */
     public byte[] asciiArmourWithError(AbstractPayment pay)
     {
+        if (pay == null)
+        {
+            error("Payment is null?");
+            return null ;
+        }
+
+        ArmouredPayment ap = new ArmouredPayment(pay);
+        return ap.encode();
+/*
         byte[] b;
         try {
-            b = asciiArmour(pay);
-        } catch (PaymentException ex) {
+        } catch (IOException ex) {
             error("Payment no good: " + ex);
             return null ;
         }
 
         return b;
+*/
     }
 
     /**
-     *  Smart decoder of SOX armoured messages.
+     *  Decoder of SOX armoured messages.
+     *  @return a good payment or null
+     *  NOT USED?
      */
-    public byte[] decodeSOXPayment(byte[] payment)
+    public AbstractPayment decodeSOXPayment(byte[] data)
     {
-        byte[] thing;
-        String pay = new String(payment);
-
-        //
-        // Here, get smart.  For the moment, there are only two methods.
-        //
-        try {
-            thing = Armoury.decode(pay);
-            return thing;
-        } catch (Exception ex) { }
-
-        logmsg("failed on Armoury.decode (" + Armoury.getErrors() +
-               "), trying decodeByteArray");
+        if (data == null)
+        {
+            logmsg("decodeSOXPayment(null) ?");
+            return null;
+        }
 
+        ArmouredPayment ap;
         try {
-            thing = Armoury.decodeByteArray(SOX_MESSAGE, pay);
-            return thing;
-        } catch (Exception ex) { }
+            ap = new ArmouredPayment(data);
+        } catch (SOXPacketException ex) {
+            logmsg("SOXPEx: " + ex);
+            return null;
+        }
 
-        logmsg("failed on Armoury.decodeByteArray (" + Armoury.getErrors());
+        AbstractPayment pay = ap.getPay();
 
-        return null;
+        return pay;
     }
 
 
 
 ///////////  Deposit  //////////////////////////////////////////
 
-    public void makeDeposit(byte[] payment, AccountInfo callerAc, byte[] desc)
+    /**
+     *  Do a deposit.
+     *
+     *  High level wallet.
+     */
+    public void makeDeposit(byte[] payBuf, AccountInfo callerAc, byte[] desc)
     {
         if (isClosed())
         {
@@ -1251,22 +1265,31 @@
             return ;
         }
 
-        byte[] buf = decodeSOXPayment(payment);
-        if (buf == null)
+        /**
+         *  Recover the payment first.
+         */
+        if (payBuf == null || payBuf.length == 0)
         {
-            error("this is not an Ascii-armoured Payment.");
+            error("data is empty, not an Ascii-armoured Payment.");
             return ;
         }
 
-        Payment pay;
+        ArmouredPayment ap;
         try {
-            pay = new Payment(buf);
+            ap = new ArmouredPayment(payBuf);
         } catch (SOXPacketException ex) {
-            ex.printStackTrace();
-            error("not recoverable: " + ex);
-            return ;
+            logmsg("SOXPEx: " + ex);
+            return;
         }
 
+        AbstractPayment pay = ap.getPay();
+        if (!isTestMode() && ! (pay instanceof Payment))
+        {
+            error("Sorry, cannot deposit payments of type: " +
+                  pay.getClass() + " as yet");
+            return;
+        }
+
         AccountId ptt = pay.getTarget();
         AccountId pss = pay.getSource();
 
@@ -1527,88 +1550,36 @@
      *  Deposit the given payment.
      *  Method for sophisticated Wallet users (Teller, etc) should not use GUI.
      *
-     *  @param payment for deposit
+     *  @param pay for deposit
      *  @param account is the account to use
      *  @param desc description
      *  @param idempotentId is suggested id for deposit, ignored if null/empty
      */
-    public Receipt doDeposit(Payment payment, AccountId account, 
+    public Receipt doDeposit(AbstractPayment pay, AccountId account, 
                              byte[] desc, String idempotentId)
         throws DepositException
     {
         if (isClosed())
             throw new DepositException(WalletException.CLOSED, closeReason());
 
+        if (!isTestMode() && ! (pay instanceof Payment))
+            throw new DepositException(webfunds.sox.Errors.ERROR_NOT_SUPPORTED,
+                                       "not SOX Cheque?");
+
         ENTER("doDeposit");
-        TRACE("payment="  + payment  + 
+        TRACE("payment="  + pay  + 
             ", account=" + account+ 
             ", desc   ="     + desc     );
 
-        Payment pay = payment;
         Account ac;
         try {
             ac = getAccount(account);
         } catch (StoreException ex) {
             ex.printStackTrace(System.err);
             throw new Panic("cannot get account " + account +
-                            " payment " + payment + "\n" + ex);
+                            " payment " + pay + "\n" + ex);
         }
 
-//        AccountId ptt = pay.getTarget();
-//        AccountId pss = pay.getSource();
-//
-//
-//        //
-//        //  Acquire the account which does the deposit.
-//        //  This might not be a participant in the activity.
-//        //  Which makes it terribly complex.
-//        //  Maybe this should be banned, or another flexible
-//        //  interface provided.
-//        //
-//        Account ac;
-//        boolean knownAccount = true;  // following code should work, except...
-//        try
-//        {
-//            if (ptt.isBearer())
-//            {
-//                System.err.println("it's a bearer payment!");
-//                // Ok, so it's bearer, and we can deposit it anywhere.
-//                ac = getAccount(accountToUse);
-//
-//                if (ac == null)
-//                    throw new Panic("no target for bearer");
-//
-//                // this is who we are going to deposit the bearer into
-//                //pt = new AccountInfo(ptt, null, this);
-//                knownAccount = true;
-//            }
-//            else
-//            {
-//                System.err.println("JCvG: it's not a bearer payment");
-//                //
-//                //  We need to acquire an account, so as to get a
-//                //  subaccount, so as to do a deposit.  It doesn't
-//                //  actually make much difference which sub account
-//                //  does the deposit, as the issuer checks that the
-//                //  payment is good, not the deposit (unless bearer).
-//                //  But, it's nice for the receipt if it is all
-//                //  aligned.
-//                //
-// // was this back to front?  Should look at target first...
-//                ac = getAccount(pss);
-//                if (ac == null)                      // not our target
-//                {
-//                    ac = getAccount(ptt);
-//                    if(ac == null)
-//                        throw new DepositException(
-//                            DepositException.UNKNOWN_ACCOUNT);
-//                }
-//            }
-//        }
-//        catch (StoreException ex)
-//        {
-//            throw new Panic("cannot recover accounts? " + ex);
-//        }
 
 
         String choice = ac.getName();



1.52      +10 -7     java/webfunds/ricardian/Contract.java

Index: Contract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/Contract.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- Contract.java	2001/03/18 03:13:44	1.51
+++ Contract.java	2001/03/18 23:23:12	1.52
@@ -1,4 +1,4 @@
-/* $Id: Contract.java,v 1.51 2001/03/18 03:13:44 iang Exp $
+/* $Id: Contract.java,v 1.52 2001/03/18 23:23:12 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -37,15 +37,16 @@
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 
+import webfunds.util.Armoury;
+
 import webfunds.utils.Debug;
 import webfunds.utils.Hex;
 import webfunds.utils.Panic;
 
-import webfunds.sox.Armoury;
 import webfunds.sox.Crypto;
 import webfunds.sox.ItemId;
 import webfunds.sox.SOXKeyException;
-import webfunds.sox.utils.Base64;
+import webfunds.util.Base64Coder;
 
 import cryptix.openpgp.PGPUserID;
 import cryptix.openpgp.PGPKeyID;
@@ -321,8 +322,9 @@
 
     public String fileNameFromDigest(byte[] hash)
     {
-        String s = Base64.encode(hash);
-        byte b[]  = Base64.decode(s);
+        Base64Coder b64 = new Base64Coder();
+        String s = b64.encode(hash);
+        byte b[]  = b64.decode(s);
         if (!Support.equals(b, hash))
             throw new RuntimeException("Base64 failed: " +
                       name + " ==> " + fileName + " ==> " + Hex.data2hex(b));
@@ -379,7 +381,8 @@
             canonical2 = prepareContractForCanonicalDigest2(txt);
         } catch (IOException ex) {
             ex.printStackTrace(System.err);
-            throw new RuntimeException("Armoury.prepareDataToSign: " + ex);
+            throw new RuntimeException(
+                                 "prepareContractForCanonicalDigest2: " + ex);
         }
 
 
@@ -1781,7 +1784,7 @@
                                        "base part empty or too small");
             if (payload.equals(contract))   // traps rescursion?
                  throw new ContractException(ContractException.NOT_A_CONTRACT,
-                                       "Armoury failed to unsign!");
+                                       "PGPArmoury failed to unsign!");
 
             return getBase(payload); //  RECURSIVE !?!
         }



1.73      +5 -3      java/webfunds/sox/Account.java

Index: Account.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Account.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- Account.java	2000/10/14 01:39:46	1.72
+++ Account.java	2001/03/18 23:23:12	1.73
@@ -1,4 +1,4 @@
-/* $Id: Account.java,v 1.72 2000/10/14 01:39:46 iang Exp $
+/* $Id: Account.java,v 1.73 2001/03/18 23:23:12 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team. All rights reserved.
@@ -18,14 +18,16 @@
 import java.util.Hashtable;
 import java.util.Vector;
 
+import webfunds.util.Armoury;
 
+
 /**
  * This class contains all information needed about an
  * account in order to be able to generate authentication
  * information, except perhaps for holding a key passphrase,
  * which is not stored in the Store (only in a runtime object).
  *
- * @version $Revision: 1.72 $
+ * @version $Revision: 1.73 $
  * @author  Jeroen C. van Gelderen (gelderen@webfunds.org)
  * @author  Unknown
  */
@@ -449,7 +451,7 @@
         }
         else // 3 and earlier.  certs.  caused indeterminable exceptions
         {
-            Certificate cert = Utils.getCertificate(b);
+            Certificate cert = Armoury.getCertificate(b);
             pubKey = Crypto.getPublicKeyFromCert(cert);
             try {
                 id = new AccountId(pubKey);



1.17      +7 -4      java/webfunds/sox/ItemId.java

Index: ItemId.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/ItemId.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ItemId.java	2001/02/27 14:13:38	1.16
+++ ItemId.java	2001/03/18 23:23:12	1.17
@@ -1,5 +1,5 @@
 /*
- * $Id: ItemId.java,v 1.16 2001/02/27 14:13:38 iang Exp $
+ * $Id: ItemId.java,v 1.17 2001/03/18 23:23:12 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -8,19 +8,22 @@
 
 import java.io.*;
 
+import webfunds.util.Armoury;
 
 /**
  * This class represents an Item identifer,
  * which is the standard way of refering to an item.
  *
- * @version $Revision: 1.16 $
+ * @version $Revision: 1.17 $
  */
 public class ItemId
     extends Id
 {
 
-    // this method doesn't really belong in sox
-    // as it assumes Ricardian concepts
+    /**
+     *  XXX: this method doesn't really belong in sox
+     *  as it assumes Ricardian concepts
+     */
     public static ItemId newInstance(byte[] txt)
         throws IOException
     {