[Webfunds-commits] java/webfunds/sox Receipt.java
Ian Grigg
iang@cypherpunks.ai
Fri, 13 Oct 2000 21:31:07 -0400 (AST)
iang 00/10/13 21:31:07
Modified: webfunds/sox Receipt.java
Log:
added (silent, innocuous) code to carry the Proto payment within Receipt.
Revision Changes Path
1.40 +80 -44 java/webfunds/sox/Receipt.java
Index: Receipt.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Receipt.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- Receipt.java 2000/06/18 21:57:17 1.39
+++ Receipt.java 2000/10/14 01:31:06 1.40
@@ -1,5 +1,5 @@
/*
- * $Id: Receipt.java,v 1.39 2000/06/18 21:57:17 iang Exp $
+ * $Id: Receipt.java,v 1.40 2000/10/14 01:31:06 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -18,17 +18,35 @@
* data received from the issuer.
*/
public class Receipt
- extends Encodable implements Serializable
+ extends Encodable // implements Serializable
{
/**
- * The version of the encoded receipt
- */
- protected static final int VERSION = 2;
+ * The version of the encoded receipt.
+ *
+ * 1 - original, as delivered, no version.
+ * 2 - added MD_SHA1 signature
+ * 3 - adds Proto-payment option
+ * 4 - use me next
+ */
+ public static final int
+ RECEIPT_ORIGINAL = 1, // number never used
+ RECEIPT_LOCAL_VERS = 2, // added MD_SHA1 sig
+ RECEIPT_PROTO = 3, // includes ProtoPay
+ RECEIPT_not_used_yet = 4; // use me next...
+
+ protected int version = RECEIPT_LOCAL_VERS; // change this if an old packet
+
+ public int getVersion() { return version; }
+
+
protected static final int MD_SHA1 = 2;
protected DepositRequest depositRequest;
protected byte[] depositRequestData;
+ protected AbstractPayment protoPayment;
+ protected byte[] protoPaymentData;
+
protected ItemId item;
protected long qty;
protected long timestamp;
@@ -42,13 +60,28 @@
protected AccountId tgt;
protected AccountId src;
+ /**
+ * Some flags to indicate special conditions.
+ */
+ protected long flags;
+ public static final long
+ WITHDRAW_PROTO = 1; // receipt has ProtoPay
+
+ protected boolean isSet(long i) { return (flags & i) == i; }
+ public boolean isWithdrawalReceipt() { return isSet(WITHDRAW_PROTO); }
/**
- * Get the Payment that was deposited
+ * Get the Payment that was deposited.
*/
public Payment getPayment() { return depositRequest.getPayment(); }
/**
+ * Get the Proto-Payment if the original request was a WithdrawalRequest.
+ */
+ public AbstractPayment getProtoPayment() { return protoPayment; }
+ public void setProtoPayment(AbstractPayment p) { protoPayment = p; }
+
+ /**
* Get the DepositRequest object that was used to deposit the payment
*
* The DepositRequest is the signed object
@@ -69,10 +102,7 @@
public String getPaymentId() { return pid; }
/**
- * Get the identifier on the deposit request, as created by the payee
- *
- * Note: although a java String is used, this identifier
- * should only contain 8-bit ascii characters.
+ * Get the identifier on the deposit request, as created by the payee.
*/
public String getDepositId() { return did; }
@@ -88,38 +118,38 @@
public String getTransactionId() { return xid; }
/**
- * Get the account from which the transaction was drawn
+ * Get the account from which the transaction was drawn.
*/
public AccountId getTarget() { return tgt; }
/**
- * Get the account to which the payment was made
+ * Get the account to which the payment was made.
*/
public AccountId getSource() { return src; }
/**
- * Get the type of item (or "currency") of the transaction
- * (e.g. airmiles)
+ * Get the type of item (or "currency") of the transaction.
+ * This is normally the hash of the Ricardian Contract.
*/
public ItemId getItem() { return item; }
/**
- * Get the quantity of the item for the transaction
+ * Get the quantity of the item for the transaction.
*/
public long getQty() { return qty; }
/**
- * Get the description on the payment
+ * Get the description on the payment.
*/
public byte[] getPaymentDesc() { return depositRequest.getPaymentDesc(); }
/**
- * Get the description on the deposit request
+ * Get the description on the deposit request.
*/
public byte[] getDepositDesc() { return depositRequest.getDepositDesc(); }
/**
- * Get the time and date of the transaction
+ * Get the time and date of the transaction.
*/
public long getTimestamp()
{
@@ -130,7 +160,13 @@
}
protected PrintWriter debug;
- void logmsg(String s) { if (debug != null) debug.println(s); else System.err.println(s); }
+ void logmsg(String s)
+ {
+ if (debug != null)
+ debug.println(s);
+ else
+ System.err.println(s);
+ }
public boolean isValid()
@@ -246,12 +282,14 @@
long time = getTimestamp();
if ( ! (from < time && time < till) &&
time > new Long("929803829000").longValue() )
-//{
-//Payment p = depositRequest.getPayment();
-//System.err.println("PPPPP " + p);
+ {
throw new SOXPacketException("Time out of range: "+time+
" not in "+from+","+till);
-//}
+ }
+
+ protoPayment = null;
+ protoPaymentData = null;
+ flags = 0;
}
/**
@@ -377,10 +415,13 @@
dis = new DataInputStream(d2);
int v = dis.readUnsignedByte();
- //byte[] two = { (byte)2 };
- if (v != VERSION)
+ if ( !(RECEIPT_LOCAL_VERS <= v && v <= RECEIPT_PROTO) )
throw new SOXPacketException(
- "Invalid version number " + VERSION + " != " + v);
+ "Invalid version number {" +
+ RECEIPT_LOCAL_VERS + "-" + RECEIPT_PROTO + "} != " + v);
+
+ if (v >= RECEIPT_PROTO)
+ flags = dis.readLong();
//
// Perl code shoves a one byte Message Digest Type in front of hashes.
@@ -411,6 +452,13 @@
depositRequestData = readByteArray(dis);
depositRequest = new DepositRequest(depositRequestData);
+
+ if (version >= RECEIPT_PROTO && isWithdrawalReceipt())
+ {
+ protoPaymentData = readByteArray(dis);
+ protoPayment = new Payment(protoPaymentData);
+ }
+
sig = readByteArray(dis);
byte[] my_sig = getHashSig();
@@ -422,23 +470,6 @@
webfunds.utils.Hex.data2hex(sig) + " (=packet)");
}
-// ByteArrayInputStream bais = new ByteArrayInputStream(sig);
-// hash_type = bais.read();
-// if (MD_SHA1 != hash_type)
-// throw new SOXPacketException(
-// "Unknown Hash type: SHA=2 != " + hash_type);
-// byte[] md = readByteArray(new DataInputStream(bais));
-//
-// byte[] data = encode_data_for_signing();
-// byte[] new_sig = Crypto.digest(data);
-//
-// if (!Utils.byteEquals(new_sig, md))
-// {
-// throw new SOXPacketException("Sig Check Failed: (calc=) " +
-// webfunds.utils.Hex.data2hex(new_sig) + " != " +
-// webfunds.utils.Hex.data2hex(md) + " (=packet)");
-// }
-
if (!isValid())
{
throw new SOXPacketException("Dud Receipt");
@@ -499,7 +530,10 @@
throws IOException
{
DataOutputStream dos = new DataOutputStream(os);
- dos.writeByte(VERSION);
+ dos.writeByte(version);
+
+ if (version >= RECEIPT_PROTO)
+ dos.writeLong(flags);
dos.writeByte(MD_SHA1);
item.encode(dos);
@@ -517,6 +551,8 @@
// written as array, as original might vary on encode()
writeByteArray(dos, depositRequestData);
+ if (version >= RECEIPT_PROTO && isWithdrawalReceipt())
+ writeByteArray(dos, protoPaymentData);
}
/**