[Webfunds-commits] java/webfunds/token/algorithm AbstractParamInterface.java AbstractBlindedToken.java AbstractPrivateTokenParameters.java AbstractPublicTokenParameters.java AbstractToken.java AbstractTokenUtil.java ChaumPrivateTokenParameters.java RandomPrivateTokenParameters.java
Edwin Woudt
edwin@cypherpunks.ai
Wed, 3 Jan 2001 21:16:11 -0400 (AST)
edwin 01/01/03 21:16:11
Modified: webfunds/token/algorithm AbstractBlindedToken.java
AbstractPrivateTokenParameters.java
AbstractPublicTokenParameters.java
AbstractToken.java AbstractTokenUtil.java
ChaumPrivateTokenParameters.java
RandomPrivateTokenParameters.java
Added: webfunds/token/algorithm AbstractParamInterface.java
Log:
Completion of abstract parameter classes.
Revision Changes Path
1.4 +6 -6 java/webfunds/token/algorithm/AbstractBlindedToken.java
Index: AbstractBlindedToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractBlindedToken.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractBlindedToken.java 2001/01/03 02:19:19 1.3
+++ AbstractBlindedToken.java 2001/01/04 01:16:10 1.4
@@ -1,4 +1,4 @@
-/* $Id: AbstractBlindedToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
+/* $Id: AbstractBlindedToken.java,v 1.4 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -13,7 +13,7 @@
/**
* Class description
*
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
public abstract class AbstractBlindedToken implements AbstractTokenInterface {
@@ -107,11 +107,11 @@
}
public final byte getImplementationMajorVersion() {
- return abstractMajorVersion;
+ return implementationMajorVersion;
}
public final byte getImplementationMinorVersion() {
- return abstractMajorVersion;
+ return implementationMajorVersion;
}
public final byte[] getCurrencyID() {
@@ -135,11 +135,11 @@
}
public final void setImplementationMajorVersion(byte x) {
- this.abstractMajorVersion = x;
+ this.implementationMajorVersion = x;
}
public final void setImplementationMinorVersion(byte x) {
- this.abstractMajorVersion = x;
+ this.implementationMajorVersion = x;
}
public final void setCurrencyID(byte[] x) {
1.3 +110 -474 java/webfunds/token/algorithm/AbstractPrivateTokenParameters.java
Index: AbstractPrivateTokenParameters.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractPrivateTokenParameters.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractPrivateTokenParameters.java 2001/01/03 02:19:19 1.2
+++ AbstractPrivateTokenParameters.java 2001/01/04 01:16:10 1.3
@@ -1,4 +1,4 @@
-/* $Id: AbstractPrivateTokenParameters.java,v 1.2 2001/01/03 02:19:19 edwin Exp $
+/* $Id: AbstractPrivateTokenParameters.java,v 1.3 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -22,169 +22,50 @@
/**
* Abstraction for private (key) data.
*
- * <p>
- * This class (and it's sister AbstractPublicTokenParameters) provide an
- * abstraction for series-wide data used by the blinding protocol. This is
- * usually somewhat related to cryptographic keys, but it can be any information
- * the particular protocol needs.
- * </p><p>
- * For each series of tokens a pair of AbstractPrivateTokenParameters and
- * AbstractPublicTokenParameters objects will be created. The private object is
- * kept at the server and used to sign the tokens, the public object is sent to
- * the client and used by the client to construct the protocoins and to verify
- * that the server doesn't cheat. A subclass will thus have to add it's own
- * methods to provide the protocol-specific data to it's Token counterparts.
- * </p><p>
- * There is no need to store cryptographic keys in this class for transport
- * security as subclasses can assume that all traffic between client and server
- * will be encrypted by the application. This class does however handle the
- * signing of the public data.
- * </p><p>
- * In the remainder of this file, two groups of programmers will be used for
- * specific notes and instuctions: users and developers. Users are programmers
- * who develop applications that use these classes. Developers are programmers
- * who extend these classes to add a new blinding protocol.
- * </p><p>
- * <h3>State diagram</h3>
- * </p><p>
- * The state diagram below details in what order methods can be called.
- * After constructing the object, it is in the 'EMPTY' state.
- * </p>
- * <pre>Legend: X = method call allowed in this state
- * - = method call causes transition to this state (if no minus is
- * present for a certain method than no transition will occur)
- *
- * EMPTY NOSIG SIGNED DECOD1 DECOD2 READ
- * generate X -
- * decode (1) X -
- * decodePrivateImpl (1) X -
- * decodePublicImpl (1) X -
- * EMPTY NOSIG SIGNED DECOD1 DECOD2 READ
- * getDenominations X X X
- * getSeries X X X
- * getExpiryDate X X X
- * EMPTY NOSIG SIGNED DECOD1 DECOD2 READ
- * sign X -
- * verify X X X X
- * EMPTY NOSIG SIGNED DECOD1 DECOD2 READ
- * encodePublicDataImpl X
- * encodePublicData X
- * encodePrivateDataImpl X
- * encodePrivateData X
- * EMPTY NOSIG SIGNED DECOD1 DECOD2 READ
- * Other methods (2) X
- * EMPTY NOSIG SIGNED DECOD1 DECOD2 READ
- *
- * </pre>
- * <p>
- * Notes:<br>
- * (1): decode calls decodePrivateImpl and decodePublicImpl (in that order), so
- * in fact three state transitions will occure on one call to decode
- * (2): other methods are subclass specific methods that provide protocol
- * specific data. <br>
- * </p>
- *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
-public abstract class AbstractPrivateTokenParameters {
-
-// Constants
-//.............................................................................
-
- /**
- * Major version number. Upping this number will cause older clients to
- * reject a particular set of data.
- *
- * Note that this version number is only used between
- * AbstractPrivateTokenParameters and AbstractPublicTokenParameters.
- * Subclasses should implement their own versioning scheme.
- */
- /* package */ static final int MAJOR_VERSION = 1;
-
- /**
- * Minor version number. Upping this number will NOT cause older clients to
- * reject a particular set of data.
- *
- * Note that this version number is only used between
- * AbstractPrivateTokenParameters and AbstractPublicTokenParameters.
- * Subclasses should implement their own versioning scheme.
- */
- /* package */ static final int MINOR_VERSION = 0;
-
+public abstract class AbstractPrivateTokenParameters
+implements AbstractParamInterface {
// Instance variables
//.............................................................................
- /** Contains the binary signature data */
private byte[] sigdata = null;
- /** Contains the binary private data */
private byte[] privdata = null;
- /** Contains the binary public data */
private byte[] pubdata = null;
+
+ private byte[] currencyID;
+ private byte[] series;
+ private Date expiry;
+ private long[] denominations;
+
+ private byte abstractMajorVersion;
+ private byte abstractMinorVersion;
+ private byte implementationMajorVersion;
+ private byte implementationMinorVersion;
// Abstract init methods
//.............................................................................
+
+ protected abstract void generateImpl(SecureRandom sr, long[] denominations);
+
+ public final void generate(SecureRandom sr, long[] denominations,
+ byte[] currencyID, byte[] series, Date expiry)
+ {
+ this.currencyID = currencyID;
+ this.series = series;
+ this.expiry = expiry;
+ this.denominations = denominations;
+ generateImpl(sr, denominations);
+ }
+
- /**
- * Generate a new set of data.
- *
- * @param sr A source of randomness
- * @param denominations A list of denominations for which parameters have
- * to be generated.
- * @param series An identifier that uniquely identifies this series.
- * @param expiry The date on which this series will expire. If it
- * will not expire or if expiration is not determined
- * in advance, a null value should be given for this
- * parameter.
- */
- public abstract void generate(SecureRandom sr, long[] denominations,
- long series, Date expiry);
-
-
- /**
- * Decode the private data.
- *
- * <p>This method will be given the result of an earlier encodePrivateImpl
- * call.</p>
- *
- * @param data The array that contains the data.
- * @param start The position in the array where the data starts.
- * @param len The length of the data. If the implementation wants to read
- * more data than available, it should throw a
- * DataFormatException. If there is some extra data at the end
- * it is left up to the implementation to decide if the extra
- * data is ignored or a DataFormatException is thrown.
- *
- * @throws DataFormatException If the data is incorrectly formatted.
- * @throws UnsupportedVersionException If the data contains an unsupported
- * version. This assumes that the implementation does have some sort
- * of versioning system.
- */
protected abstract void decodePrivateImpl(byte[] data, int start, int len)
throws DataFormatException, UnsupportedVersionException;
- /**
- * Decode the public data.
- *
- * <p>This method will be given the result of an earlier encodePublicImpl
- * call.</p>
- *
- * @param data The array that contains the data.
- * @param start The position in the array where the data starts.
- * @param len The length of the data. If the implementation wants to read
- * more data than available, it should throw a
- * DataFormatException. If there is some extra data at the end
- * it is left up to the implementation to decide if the extra
- * data is ignored or a DataFormatException is thrown.
- *
- * @throws DataFormatException If the data is incorrectly formatted.
- * @throws UnsupportedVersionException If the data contains an unsupported
- * version. This assumes that the implementation does have some sort
- * of versioning system.
- */
protected abstract void decodePublicImpl(byte[] data, int start, int len)
throws DataFormatException, UnsupportedVersionException;
@@ -197,26 +78,6 @@
protected abstract byte[] encodePrivateDataImpl();
-// Information retrieval methods
-//.............................................................................
-
- public final byte[] getCurrencyID() {
- throw new RuntimeException("NYI");
- }
-
- public final byte[] getSeries() {
- throw new RuntimeException("NYI");
- }
-
- public final Date getExpiryDate() {
- throw new RuntimeException("NYI");
- }
-
- public final long[] getDenominations() {
- throw new RuntimeException("NYI");
- }
-
-
// Signature methods
//.............................................................................
@@ -226,26 +87,6 @@
InvalidKeyException
{
- // @@@ ASSERT
- if (pk == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (alg == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (sr == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (sigdata != null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata != null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (privdata != null)
- throw new InternalError("Assertion failed");
-
-
Signature sig;
if (provider == null) {
sig = Signature.getInstance(alg);
@@ -264,10 +105,7 @@
pubdata = encodePublicDataImpl();
// Fetching the private here does not make much sense at first sight
- // because we don't need it for signing. However, this method results
- // in a state transition to the SIGNED state and in that state it is
- // not correct anymore to call encodePrivateDataImpl() as is defined
- // at the top of this file.
+ // because we don't need it for signing.
// The reasoning behind this is that maybe someday it does make sense
// to sign the private data as well.
privdata = encodePrivateDataImpl();
@@ -286,17 +124,6 @@
"happen. "+se);
}
-
- // @@@ ASSERT
- if (sigdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (privdata == null)
- throw new InternalError("Assertion failed");
-
}
public final boolean verify(PublicKey pk, String alg, String provider)
@@ -304,23 +131,6 @@
InvalidKeyException, SignatureException
{
- // @@@ ASSERT
- if (sigdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (privdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pk == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (alg == null)
- throw new InternalError("Assertion failed");
-
-
Signature sig;
if (provider == null) {
sig = Signature.getInstance(alg);
@@ -341,277 +151,103 @@
public final void decode(byte[] data, int start, int len)
throws DataFormatException, UnsupportedVersionException
{
-
- // @@@ ASSERT
- if (sigdata != null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata != null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (privdata != null)
- throw new InternalError("Assertion failed");
-
+ int delta = AbstractTokenUtil.decodeParams(data, start, len,
+ AbstractTokenUtil.PKT_PRIVATEPARAMS, this);
+ start += delta; len -= delta;
- // read and check identifier and version
+ int privlen = EncodeDecodeUtil.decodeInt(data, start, len);
+ start += 4; len -= 4;
- if (len < 8) throw new DataFormatException("Blob too small");
+ decodePrivateImpl(data, start, privlen);
+ start += privlen; len -= privlen;
- int pos = start;
-
- if ((data[pos++] != 84) && // 'T'
- (data[pos++] != 75) && // 'K'
- (data[pos++] != 83) && // 'S'
- (data[pos++] != 68)) // 'D'
- {
- throw new DataFormatException("Wrong identifier string");
- }
-
- int majorVersion = (((int)(data[pos++])) << 8) + ((int)(data[pos++]));
- int minorVersion = (((int)(data[pos++])) << 8) + ((int)(data[pos++]));
-
- if (majorVersion > MAJOR_VERSION) {
- throw new UnsupportedVersionException("Unsupported version");
- }
+ int publen = EncodeDecodeUtil.decodeInt(data, start, len);
+ start += 4; len -= 4;
+ decodePublicImpl(data, start, publen);
+ start += publen; len -= publen;
+ }
- // read private data
-
- if (pos+4 > start+len)
- throw new DataFormatException("Blob too small");
-
- int lenpriv = (((int)(data[pos++])) << 24) +
- (((int)(data[pos++])) << 16) +
- (((int)(data[pos++])) << 8) +
- (((int)(data[pos++])) << 0);
-
- if (pos+lenpriv > start+len)
- throw new DataFormatException("Blob too small");
-
- privdata = new byte[lenpriv];
- System.arraycopy(data, pos, privdata, 0, lenpriv);
- pos += lenpriv;
-
+ public final byte[] encodePublicData() {
- // read public data
-
- if (pos+4 > start+len)
- throw new DataFormatException("Blob too small");
-
- int lenpub = (((int)(data[pos++])) << 24) +
- (((int)(data[pos++])) << 16) +
- (((int)(data[pos++])) << 8) +
- (((int)(data[pos++])) << 0);
-
- if (pos+lenpub > start+len)
- throw new DataFormatException("Blob too small");
-
- pubdata = new byte[lenpub];
- System.arraycopy(data, pos, pubdata, 0, lenpub);
- pos += lenpub;
-
+ return AbstractTokenUtil.encodeParams(pubdata, null,
+ AbstractTokenUtil.PKT_PUBLICPARAMS, this);
+ }
+
+ public final byte[] encodePrivateData() {
- // read signature data
-
- if (pos+4 > start+len)
- throw new DataFormatException("Blob too small");
-
- int lensig = (((int)(data[pos++])) << 24) +
- (((int)(data[pos++])) << 16) +
- (((int)(data[pos++])) << 8) +
- (((int)(data[pos++])) << 0);
-
- if (pos+lensig > start+len)
- throw new DataFormatException("Blob too small");
-
- sigdata = new byte[lensig];
- System.arraycopy(data, pos, sigdata, 0, lensig);
- pos += lensig;
-
-
- // If this is a future version, more data could follow.
- // However, if we know the version, then check if we've reached the end.
- if ((minorVersion <= MINOR_VERSION) || (majorVersion < MAJOR_VERSION)) {
- if (pos != start+len) {
- throw new DataFormatException("Blob too large");
- }
- }
-
-
- // Call the decode methods of the subclass
- decodePrivateImpl(privdata, 0, privdata.length);
- decodePublicImpl(pubdata, 0, privdata.length);
-
+ return AbstractTokenUtil.encodeParams(pubdata, privdata,
+ AbstractTokenUtil.PKT_PRIVATEPARAMS, this);
+ }
- // @@@ ASSERT
- if (sigdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (privdata == null)
- throw new InternalError("Assertion failed");
- }
+// Getters / Setters
+//.............................................................................
- public final byte[] encodePublicData() {
-
- // @@@ ASSERT
- if (pubdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (sigdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata.length <= 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (sigdata.length <= 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (MAJOR_VERSION < 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (MINOR_VERSION < 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT ### FIXME: support versions > 255
- if (MAJOR_VERSION > 255)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT ### FIXME: support versions > 255
- if (MINOR_VERSION > 255)
- throw new InternalError("Assertion failed");
-
-
- byte[] id = {84, 75, 80, 68}; // 'TKPD' = ToKen Public Data
- // ### FIXME: support versions > 255
- byte[] version = { 0, MAJOR_VERSION, 0, MINOR_VERSION};
-
- byte[] lenpub = new byte[4];
- lenpub[0] = (byte)((pubdata.length >> 24) & 0xFF);
- lenpub[1] = (byte)((pubdata.length >> 16) & 0xFF);
- lenpub[2] = (byte)((pubdata.length >> 8) & 0xFF);
- lenpub[3] = (byte)((pubdata.length >> 0) & 0xFF);
-
- byte[] lensig = new byte[4];
- lensig[0] = (byte)((sigdata.length >> 24) & 0xFF);
- lensig[1] = (byte)((sigdata.length >> 16) & 0xFF);
- lensig[2] = (byte)((sigdata.length >> 8) & 0xFF);
- lensig[3] = (byte)((sigdata.length >> 0) & 0xFF);
-
- byte[] result = new byte[id.length + version.length
- + lenpub.length + pubdata.length
- + lensig.length + sigdata.length];
-
- int pos = 0;
-
- System.arraycopy(id, 0, result, pos, id.length);
- pos += id.length;
- System.arraycopy(id, 0, result, pos, version.length);
- pos += version.length;
-
- System.arraycopy(id, 0, result, pos, lenpub.length);
- pos += lenpub.length;
- System.arraycopy(id, 0, result, pos, pubdata.length);
- pos += pubdata.length;
-
- System.arraycopy(id, 0, result, pos, lensig.length);
- pos += lensig.length;
- System.arraycopy(id, 0, result, pos, sigdata.length);
- pos += sigdata.length;
-
- // @@@ ASSERT
- if (pos != result.length) throw new
- InternalError("Assertion failed");
+ public final byte[] getCurrencyID() {
+ return currencyID;
+ }
- return result;
-
+ public final byte[] getSeries() {
+ return series;
}
-
- public final byte[] encodePrivateData() {
-
- // @@@ ASSERT
- if (pubdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (sigdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata.length <= 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (sigdata.length <= 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (MAJOR_VERSION < 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (MINOR_VERSION < 0)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT ### FIXME: support versions > 255
- if (MAJOR_VERSION > 255)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT ### FIXME: support versions > 255
- if (MINOR_VERSION > 255)
- throw new InternalError("Assertion failed");
-
-
- byte[] id = {84, 75, 83, 68}; // 'TKSD' = ToKen Secret Data
- // ### FIXME: support versions > 255
- byte[] version = { 0, MAJOR_VERSION, 0, MINOR_VERSION};
-
- byte[] lenpriv = new byte[4];
- lenpriv[0] = (byte)((pubdata.length >> 24) & 0xFF);
- lenpriv[1] = (byte)((pubdata.length >> 16) & 0xFF);
- lenpriv[2] = (byte)((pubdata.length >> 8) & 0xFF);
- lenpriv[3] = (byte)((pubdata.length >> 0) & 0xFF);
-
- byte[] lenpub = new byte[4];
- lenpub[0] = (byte)((pubdata.length >> 24) & 0xFF);
- lenpub[1] = (byte)((pubdata.length >> 16) & 0xFF);
- lenpub[2] = (byte)((pubdata.length >> 8) & 0xFF);
- lenpub[3] = (byte)((pubdata.length >> 0) & 0xFF);
-
- byte[] lensig = new byte[4];
- lensig[0] = (byte)((sigdata.length >> 24) & 0xFF);
- lensig[1] = (byte)((sigdata.length >> 16) & 0xFF);
- lensig[2] = (byte)((sigdata.length >> 8) & 0xFF);
- lensig[3] = (byte)((sigdata.length >> 0) & 0xFF);
-
- byte[] result = new byte[id.length + version.length +
- + lenpriv.length + privdata.length
- + lenpub.length + pubdata.length
- + lensig.length + sigdata.length];
-
- int pos = 0;
-
- System.arraycopy(id, 0, result, pos, id.length);
- pos += id.length;
- System.arraycopy(id, 0, result, pos, version.length);
- pos += version.length;
-
- System.arraycopy(id, 0, result, pos, lenpriv.length);
- pos += lenpriv.length;
- System.arraycopy(id, 0, result, pos, privdata.length);
- pos += privdata.length;
-
- System.arraycopy(id, 0, result, pos, lenpub.length);
- pos += lenpub.length;
- System.arraycopy(id, 0, result, pos, pubdata.length);
- pos += pubdata.length;
-
- System.arraycopy(id, 0, result, pos, lensig.length);
- pos += lensig.length;
- System.arraycopy(id, 0, result, pos, sigdata.length);
- pos += sigdata.length;
-
- // @@@ ASSERT
- if (pos != result.length) throw new
- InternalError("Assertion failed");
- return result;
+ public final Date getExpiryDate() {
+ return expiry;
+ }
+ public final long[] getDenominations() {
+ return denominations;
}
+
+ public final byte getAbstractMajorVersion() {
+ return abstractMajorVersion;
+ }
+
+ public final byte getAbstractMinorVersion() {
+ return abstractMajorVersion;
+ }
+
+ public final byte getImplementationMajorVersion() {
+ return implementationMajorVersion;
+ }
+
+ public final byte getImplementationMinorVersion() {
+ return implementationMajorVersion;
+ }
+
+ public final void setCurrencyID(byte[] x) {
+ this.currencyID = x;
+ }
+
+ public final void setSeries(byte[] x) {
+ this.series = x;
+ }
+
+ public final void setExpiryDate(Date x) {
+ this.expiry = x;
+ }
+
+ public final void setDenominations(long[] x) {
+ this.denominations = x;
+ }
+
+ public final void setAbstractMajorVersion(byte x) {
+ this.abstractMajorVersion = x;
+ }
+
+ public final void setAbstractMinorVersion(byte x) {
+ this.abstractMajorVersion = x;
+ }
+
+ public final void setImplementationMajorVersion(byte x) {
+ this.implementationMajorVersion = x;
+ }
+
+ public final void setImplementationMinorVersion(byte x) {
+ this.implementationMajorVersion = x;
+ }
+
}
1.3 +86 -120 java/webfunds/token/algorithm/AbstractPublicTokenParameters.java
Index: AbstractPublicTokenParameters.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractPublicTokenParameters.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractPublicTokenParameters.java 2001/01/03 02:19:19 1.2
+++ AbstractPublicTokenParameters.java 2001/01/04 01:16:10 1.3
@@ -1,4 +1,4 @@
-/* $Id: AbstractPublicTokenParameters.java,v 1.2 2001/01/03 02:19:19 edwin Exp $
+/* $Id: AbstractPublicTokenParameters.java,v 1.3 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -21,19 +21,28 @@
/**
* Class description
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
-public abstract class AbstractPublicTokenParameters {
+public abstract class AbstractPublicTokenParameters
+implements AbstractParamInterface {
// Instance variables
//.............................................................................
- /** Contains the binary signature data */
private byte[] sigdata = null;
- /** Contains the binary public data */
private byte[] pubdata = null;
+ private byte[] currencyID;
+ private byte[] series;
+ private Date expiry;
+ private long[] denominations;
+
+ private byte abstractMajorVersion;
+ private byte abstractMinorVersion;
+ private byte implementationMajorVersion;
+ private byte implementationMinorVersion;
+
// Init methods
//.............................................................................
@@ -42,26 +51,6 @@
throws DataFormatException, UnsupportedVersionException;
-// Information retrieval methods
-//.............................................................................
-
- public final byte[] getCurrencyID() {
- throw new RuntimeException("NYI");
- }
-
- public final byte[] getSeries() {
- throw new RuntimeException("NYI");
- }
-
- public final Date getExpiryDate() {
- throw new RuntimeException("NYI");
- }
-
- public final long[] getDenominations() {
- throw new RuntimeException("NYI");
- }
-
-
// Signature methods
//.............................................................................
@@ -70,20 +59,6 @@
InvalidKeyException, SignatureException
{
- // @@@ ASSERT
- if (sigdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pk == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (alg == null)
- throw new InternalError("Assertion failed");
-
-
Signature sig;
if (provider == null) {
sig = Signature.getInstance(alg);
@@ -104,94 +79,85 @@
public final void decode(byte[] data, int start, int len)
throws DataFormatException, UnsupportedVersionException
{
-
- // @@@ ASSERT
- if (sigdata != null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata != null)
- throw new InternalError("Assertion failed");
+ int delta = AbstractTokenUtil.decodeParams(data, start, len,
+ AbstractTokenUtil.PKT_PRIVATEPARAMS, this);
+ start += delta; len -= delta;
+ int publen = EncodeDecodeUtil.decodeInt(data, start, len);
+ start += 4; len -= 4;
- // read and check identifier and version
-
- if (len < 8) throw new DataFormatException("Blob too small");
-
- int pos = start;
-
- if ((data[pos++] != 84) && // 'T'
- (data[pos++] != 75) && // 'K'
- (data[pos++] != 83) && // 'S'
- (data[pos++] != 68)) // 'D'
- {
- throw new DataFormatException("Wrong identifier string");
- }
-
- int majorVersion = (((int)(data[pos++])) << 8) + ((int)(data[pos++]));
- int minorVersion = (((int)(data[pos++])) << 8) + ((int)(data[pos++]));
-
- if (majorVersion > AbstractPrivateTokenParameters.MAJOR_VERSION) {
- throw new UnsupportedVersionException("Unsupported version");
- }
-
+ decodePublicImpl(data, start, publen);
+ start += publen; len -= publen;
+ }
- // read public data
-
- if (pos+4 > start+len)
- throw new DataFormatException("Blob too small");
-
- int lenpub = (((int)(data[pos++])) << 24) +
- (((int)(data[pos++])) << 16) +
- (((int)(data[pos++])) << 8) +
- (((int)(data[pos++])) << 0);
-
- if (pos+lenpub > start+len)
- throw new DataFormatException("Blob too small");
-
- pubdata = new byte[lenpub];
- System.arraycopy(data, pos, pubdata, 0, lenpub);
- pos += lenpub;
-
- // read signature data
-
- if (pos+4 > start+len)
- throw new DataFormatException("Blob too small");
-
- int lensig = (((int)(data[pos++])) << 24) +
- (((int)(data[pos++])) << 16) +
- (((int)(data[pos++])) << 8) +
- (((int)(data[pos++])) << 0);
-
- if (pos+lensig > start+len)
- throw new DataFormatException("Blob too small");
-
- sigdata = new byte[lensig];
- System.arraycopy(data, pos, sigdata, 0, lensig);
- pos += lensig;
-
-
- // If this is a future version, more data could follow.
- // However, if we know the version, then check if we've reached the end.
- if ((minorVersion <= AbstractPrivateTokenParameters.MINOR_VERSION) ||
- (majorVersion < AbstractPrivateTokenParameters.MAJOR_VERSION)) {
- if (pos != start+len) {
- throw new DataFormatException("Blob too large");
- }
- }
-
-
- decodeImpl(pubdata, 0, pubdata.length);
-
+// Getters / Setters
+//.............................................................................
+
+ public final byte[] getCurrencyID() {
+ return currencyID;
+ }
+
+ public final byte[] getSeries() {
+ return series;
+ }
- // @@@ ASSERT
- if (sigdata == null)
- throw new InternalError("Assertion failed");
- // @@@ ASSERT
- if (pubdata == null)
- throw new InternalError("Assertion failed");
+ public final Date getExpiryDate() {
+ return expiry;
+ }
+ public final long[] getDenominations() {
+ return denominations;
}
+
+ public final byte getAbstractMajorVersion() {
+ return abstractMajorVersion;
+ }
+
+ public final byte getAbstractMinorVersion() {
+ return abstractMajorVersion;
+ }
+
+ public final byte getImplementationMajorVersion() {
+ return implementationMajorVersion;
+ }
+
+ public final byte getImplementationMinorVersion() {
+ return implementationMajorVersion;
+ }
+
+ public final void setCurrencyID(byte[] x) {
+ this.currencyID = x;
+ }
+
+ public final void setSeries(byte[] x) {
+ this.series = x;
+ }
+
+ public final void setExpiryDate(Date x) {
+ this.expiry = x;
+ }
+
+ public final void setDenominations(long[] x) {
+ this.denominations = x;
+ }
+
+ public final void setAbstractMajorVersion(byte x) {
+ this.abstractMajorVersion = x;
+ }
+
+ public final void setAbstractMinorVersion(byte x) {
+ this.abstractMajorVersion = x;
+ }
+
+ public final void setImplementationMajorVersion(byte x) {
+ this.implementationMajorVersion = x;
+ }
+
+ public final void setImplementationMinorVersion(byte x) {
+ this.implementationMajorVersion = x;
+ }
+
}
1.4 +6 -6 java/webfunds/token/algorithm/AbstractToken.java
Index: AbstractToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractToken.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractToken.java 2001/01/03 02:19:19 1.3
+++ AbstractToken.java 2001/01/04 01:16:10 1.4
@@ -1,4 +1,4 @@
-/* $Id: AbstractToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
+/* $Id: AbstractToken.java,v 1.4 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -13,7 +13,7 @@
/**
* Class description
*
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
public abstract class AbstractToken implements AbstractTokenInterface {
@@ -132,11 +132,11 @@
}
public final byte getImplementationMajorVersion() {
- return abstractMajorVersion;
+ return implementationMajorVersion;
}
public final byte getImplementationMinorVersion() {
- return abstractMajorVersion;
+ return implementationMajorVersion;
}
public final byte[] getCurrencyID() {
@@ -160,11 +160,11 @@
}
public final void setImplementationMajorVersion(byte x) {
- this.abstractMajorVersion = x;
+ this.implementationMajorVersion = x;
}
public final void setImplementationMinorVersion(byte x) {
- this.abstractMajorVersion = x;
+ this.implementationMajorVersion = x;
}
public final void setCurrencyID(byte[] x) {
1.2 +112 -1 java/webfunds/token/algorithm/AbstractTokenUtil.java
Index: AbstractTokenUtil.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractTokenUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractTokenUtil.java 2001/01/03 02:19:19 1.1
+++ AbstractTokenUtil.java 2001/01/04 01:16:10 1.2
@@ -1,4 +1,4 @@
-/* $Id: AbstractTokenUtil.java,v 1.1 2001/01/03 02:19:19 edwin Exp $
+/* $Id: AbstractTokenUtil.java,v 1.2 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -11,7 +11,7 @@
/**
* Constants for the token library
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
public final class AbstractTokenUtil {
@@ -107,6 +107,117 @@
tok.setValue(EncodeDecodeUtil.decodeLong(data, start, len));
start += 8; len -= 8;
+
+ return initlen - len;
+ }
+
+
+ public static final byte[] encodeParams(byte[] pubdata, byte[] privdata,
+ byte identifier,
+ AbstractParamInterface tok)
+ {
+ int len = 0;
+ len += 1; // identifier
+ len += 4; // version info
+ len += EncodeDecodeUtil.getByteArrayLength(tok.getCurrencyID());
+ len += EncodeDecodeUtil.getByteArrayLength(tok.getSeries());
+ len += 4; // expiry data
+ len += 4; // number of denominations
+ len += 8 * tok.getDenominations().length;
+ len += EncodeDecodeUtil.getByteArrayLength(pubdata);
+ if (privdata != null)
+ len += EncodeDecodeUtil.getByteArrayLength(privdata);
+
+ byte[] output = new byte[len];
+ int start=0;
+
+ output[start++] = identifier;
+ len -= 1;
+
+ output[start++] = tok.getAbstractMajorVersion();
+ output[start++] = tok.getAbstractMinorVersion();
+ output[start++] = tok.getImplementationMajorVersion();
+ output[start++] = tok.getImplementationMinorVersion();
+ len -= 4;
+
+ int delta;
+
+ EncodeDecodeUtil.encodeByteArray(tok.getCurrencyID(), output, start);
+ delta = EncodeDecodeUtil.getByteArrayLength(tok.getCurrencyID());
+ start += delta; len -= delta;
+
+ EncodeDecodeUtil.encodeByteArray(tok.getSeries(), output, start);
+ delta = EncodeDecodeUtil.getByteArrayLength(tok.getSeries());
+ start += delta; len -= delta;
+
+ EncodeDecodeUtil.encodeDateTime(tok.getExpiryDate(), output, start);
+ start += 4; len -= 4;
+
+ long[] denoms = tok.getDenominations();
+ EncodeDecodeUtil.encodeInt(denoms.length, output, start);
+ for (int i=0; i<denoms.length; i++) {
+ EncodeDecodeUtil.encodeLong(denoms[i], output, start);
+ start += 4; len -= 4;
+ }
+
+ EncodeDecodeUtil.encodeByteArray(pubdata, output, start);
+ delta = EncodeDecodeUtil.getByteArrayLength(pubdata);
+ start += delta; len -= delta;
+
+ if (privdata != null) {
+ EncodeDecodeUtil.encodeByteArray(pubdata, output, start);
+ delta = EncodeDecodeUtil.getByteArrayLength(pubdata);
+ start += delta; len -= delta;
+ }
+
+ return output;
+ }
+
+
+ public static final int decodeParams(byte[] data, int start, int len,
+ byte identifier, AbstractParamInterface tok)
+ throws DataFormatException, UnsupportedVersionException
+ {
+ int initlen = len;
+
+ if (EncodeDecodeUtil.decodeByte(data, start++, len--) != identifier) {
+ throw new DataFormatException("Invalid identifier");
+ }
+
+ tok.setAbstractMajorVersion(
+ EncodeDecodeUtil.decodeByte(data, start++, len--));
+ tok.setAbstractMinorVersion(
+ EncodeDecodeUtil.decodeByte(data, start++, len--));
+ tok.setImplementationMajorVersion(
+ EncodeDecodeUtil.decodeByte(data, start++, len--));
+ tok.setImplementationMinorVersion(
+ EncodeDecodeUtil.decodeByte(data, start++, len--));
+
+ if (tok.getAbstractMajorVersion() > ABSTRACT_TOKEN_MAJOR_VERSION)
+ {
+ throw new UnsupportedVersionException("Decoded version " +
+ tok.getAbstractMajorVersion() + ", while I only know about "+
+ "version " + ABSTRACT_TOKEN_MAJOR_VERSION);
+ }
+
+ tok.setCurrencyID(EncodeDecodeUtil.decodeByteArray(data, start, len));
+ int delta = EncodeDecodeUtil.getByteArrayLength(data, start, len);
+ start += delta; len -= delta;
+
+ tok.setSeries(EncodeDecodeUtil.decodeByteArray(data, start, len));
+ delta = EncodeDecodeUtil.getByteArrayLength(data, start, len);
+ start += delta; len -= delta;
+
+ tok.setExpiryDate(EncodeDecodeUtil.decodeDateTime(data, start, len));
+ start += 4; len -= 4;
+
+ long[] denoms = new long[EncodeDecodeUtil.decodeInt(data, start, len)];
+ start += 4; len -= 4;
+ for (int i=0; i<denoms.length; i++) {
+ denoms[i] = EncodeDecodeUtil.decodeLong(data, start, len);
+ start += 8; len -= 8;
+ }
+ tok.setDenominations(denoms);
return initlen - len;
}
1.2 +2 -3 java/webfunds/token/algorithm/ChaumPrivateTokenParameters.java
Index: ChaumPrivateTokenParameters.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/ChaumPrivateTokenParameters.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ChaumPrivateTokenParameters.java 2000/12/31 03:54:20 1.1
+++ ChaumPrivateTokenParameters.java 2001/01/04 01:16:10 1.2
@@ -1,4 +1,4 @@
-/* $Id: ChaumPrivateTokenParameters.java,v 1.1 2000/12/31 03:54:20 edwin Exp $
+/* $Id: ChaumPrivateTokenParameters.java,v 1.2 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -15,7 +15,7 @@
/**
* Class description
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
public final class ChaumPrivateTokenParameters
@@ -25,8 +25,7 @@
// Abstract init methods
//.............................................................................
- public void generate(SecureRandom sr, long[] denominations,
- long series, Date expiry) {
+ public void generateImpl(SecureRandom sr, long[] denominations) {
throw new RuntimeException("NYI");
}
1.2 +2 -3 java/webfunds/token/algorithm/RandomPrivateTokenParameters.java
Index: RandomPrivateTokenParameters.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/RandomPrivateTokenParameters.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RandomPrivateTokenParameters.java 2000/12/31 03:54:21 1.1
+++ RandomPrivateTokenParameters.java 2001/01/04 01:16:10 1.2
@@ -1,4 +1,4 @@
-/* $Id: RandomPrivateTokenParameters.java,v 1.1 2000/12/31 03:54:21 edwin Exp $
+/* $Id: RandomPrivateTokenParameters.java,v 1.2 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -15,7 +15,7 @@
/**
* Class description
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
public final class RandomPrivateTokenParameters
@@ -25,8 +25,7 @@
// Abstract init methods
//.............................................................................
- public void generate(SecureRandom sr, long[] denominations,
- long series, Date expiry) {
+ public void generateImpl(SecureRandom sr, long[] denominations) {
throw new RuntimeException("NYI");
}
1.1 java/webfunds/token/algorithm/AbstractParamInterface.java
Index: AbstractParamInterface.java
===================================================================
/* $Id: AbstractParamInterface.java,v 1.1 2001/01/04 01:16:10 edwin Exp $
*
* Copyright (c) Systemics Ltd 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
*/
package webfunds.token.algorithm;
import java.util.Date;
/**
* Description
*
* @version $Revision: 1.1 $
* @author Edwin Woudt <edwin@webfunds.org>
*/
interface AbstractParamInterface {
byte getAbstractMajorVersion();
void setAbstractMajorVersion(byte x);
byte getAbstractMinorVersion();
void setAbstractMinorVersion(byte x);
byte getImplementationMajorVersion();
void setImplementationMajorVersion(byte x);
byte getImplementationMinorVersion();
void setImplementationMinorVersion(byte x);
byte[] getCurrencyID();
void setCurrencyID(byte[] x);
byte[] getSeries();
void setSeries(byte[] x);
Date getExpiryDate();
void setExpiryDate(Date x);
long[] getDenominations();
void setDenominations(long[] x);
}