[Webfunds-commits] java/webfunds/ricardian Contract.java

Ian Grigg iang@cypherpunks.ai
Sun, 27 Aug 2000 13:42:52 -0400 (AST)


iang        00/08/27 13:42:52

  Modified:    webfunds/ricardian Contract.java
  Log:
  manifest constants for lots of section names.

Revision  Changes    Path
1.37      +28 -14    java/webfunds/ricardian/Contract.java

Index: Contract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/Contract.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- Contract.java	2000/08/26 22:57:21	1.36
+++ Contract.java	2000/08/27 17:42:52	1.37
@@ -1,4 +1,4 @@
-/* $Id: Contract.java,v 1.36 2000/08/26 22:57:21 iang Exp $
+/* $Id: Contract.java,v 1.37 2000/08/27 17:42:52 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -69,6 +69,15 @@
 public class Contract
     extends Debug
 {
+    /**
+     *  Recognised section names (they appear in the contract with square
+     *  brackets on a line by themselves).
+     */
+    public final static String
+                               SECT_ISSUE         = "issue",
+                               SECT_KEYS          = "keys",
+                               SECT_LOCAL         = "local",
+                               SECT_APPL          = "appl";
 
     protected static final int CURRENCY_TYPE   = 0;
     protected static final int BOND_TYPE       = 1;
@@ -127,7 +136,7 @@
 
         // drop this crud when DigiGold Series 1 disappears.
         int v = CANHASH_WHITE_BUG;
-        String version = getField("local", "digest_version");
+        String version = getField(SECT_LOCAL, "digest_version");
         try {
             if (version != null && version.length() != 0)
             {
@@ -148,7 +157,7 @@
         //logmsg("fileName = " + fileName);
             
 
-        this.type           = getField("issue", "type");
+        this.type           = getField(SECT_ISSUE, "type");
         if (this.type == null || this.type.equals(""))
             throw new ContractException(ContractException.NOT_A_CONTRACT,
                                         "no [issue] type");
@@ -696,7 +705,7 @@
      */
     public String getApplicationName()
     {
-        return getField("appl", "contract_name");
+        return getField(SECT_APPL, "contract_name");
     }
 
 
@@ -719,7 +728,8 @@
 
     public final static String FIELD_TOP_LEVEL    = "certification",
                                FIELD_CONTRACT     = "contract",
-                               FIELD_SERVER       = "server_certification";
+                               FIELD_SERVER       = "server_certification",
+                               FIELD_OPERATOR     = "server_certification";
     /**
      * Each contract provides hints as to which server keys are
      * to be used.
@@ -755,24 +765,24 @@
         throws ContractException
     {
         // this is what we should do:
-        //       return getCert(FIELD_SERVER, ...);
+        //       return getCert(FIELD_OPERATOR, ...);
         // but because of an error in one of the contracts
         // we have to work out what the real field name is.
 
-        String fieldName = FIELD_SERVER;
+        String fieldName = FIELD_OPERATOR;
 
         // deprecate this with the DigiGold.asc V1.3 contract
-        String text = getField("keys", fieldName);
+        String text = getField(SECT_KEYS, fieldName);
 //logmsg("ok, got " + text + " from " + fieldName);
         if (text == null || text.length() == 0)
         {
             fieldName = "servercertifiation";    // missing _, speeling mistake
-            text = getField("keys", fieldName);
+            text = getField(SECT_KEYS, fieldName);
         }
 //logmsg("now got " + text + " from " + FS2);
         if (text == null || text.length() == 0)
             throw new ContractException(ContractException.KEY_SERVER,
-                      "cert <" + FIELD_SERVER + "> is not present");
+                      "cert <" + FIELD_OPERATOR + "> is not present");
 
         return getCertFromString(text,
                                  fieldName,  // may be the deprecated one
@@ -792,7 +802,7 @@
     private Certificate getCert(String name, int errno, String userIdTag)
         throws ContractException
     {
-        String text = getField("keys", name);
+        String text = getField(SECT_KEYS, name);
         if (text == null || text.length() == 0)
             throw new ContractException(errno,
                                         "cert <" + name + "> is not present");
@@ -801,6 +811,9 @@
     }
 
     /**
+     *  Cert is pulled from string value as raw, and slightly
+     *  cleaned up ( '- ' prefixes are removed).
+     *
      *  @param text contents of the field (right of equals)
      *  @param name of the field (left of equals)
      *  @param errno number to set in any exception
@@ -822,6 +835,7 @@
             throw new ContractException(errno,
                       "cert <" + name + "> is not present");
 
+        // twice?  Should be multiple times?  Once?
         int end = text.indexOf("- ");
         if(end >= 0)
             text = text.substring(0, end) + text.substring(end + 2);
@@ -850,7 +864,7 @@
         return cert;
     }
 
-    private Certificate getOpenPGPCertFromString(String text, String name,
+    public static Certificate getOpenPGPCertFromString(String text, String name,
                                           int errno, String userIdTag)
         throws ContractException
     {
@@ -890,7 +904,7 @@
         try {
             cert.verify(key);
         } catch (SignatureException se) {
-System.err.println("(rearmoured key) -----\n\n" + s + "\n\n");
+System.err.println("(original) - - - -\n\n" + text + "\n\n(rearmoured key) -----\n\n" + s + "\n\n");
             throw new ContractException(errno, e + "not self-signed - "+ se);
         } catch (NoSuchProviderException nspe) {
             throw new InternalError("Should not happen - "+nspe);
@@ -920,7 +934,7 @@
         return cert;
     }
 
-    private Certificate getX509CertFromString(String text, String name,
+    public static Certificate getX509CertFromString(String text, String name,
                                               int errno)
         throws ContractException
     {