Skip to content

Commit

Permalink
add some more setters/getters/deserializers for client use
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed Dec 18, 2010
1 parent 0fe6325 commit e46d01a
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/BuyMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ class BuyMessage {

~BuyMessage() { /*delete contract;*/ delete escrow; }

//BuyMessage(const string& s, const BankParameters *bankP)
// : coinPrime(bankP), contract(), escrow() {loadString(*this, s);}
BuyMessage(const string& s, const BankParameters *params) {
// need to set params for Coin contained in message
loadGZString(make_nvp("BuyMessage", *this), s);
coinPrime.setParameters(params);
}

/*! check contents (verify coin and escrow) */
bool check(const VEPublicKey* pk, const int stat, const ZZ& R) const;
Expand Down
7 changes: 6 additions & 1 deletion src/Buyer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ VECiphertext Buyer::makeEscrow() {

void Buyer::makeCoin(Wallet& w, const ZZ& R) {
// get coin from wallet
coin = w.nextCoin(R);
setCoin( w.nextCoin(R) );
}

void Buyer::setCoin(const Coin& c)
{
coin = c;
endorsement = coin.getEndorsement();
coin.unendorse();
}
Expand Down
1 change: 1 addition & 0 deletions src/Buyer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Buyer {
bool canAbortLocally() {return !inProgress; };

// setters
void setCoin(const Coin& coin);
void setTimeout() { timeout =time(NULL) + timeoutLength; }
void setSecurity(const int newstat) {stat = newstat;}
void setVEPublicKey(const VEPublicKey* newpk) {pk = newpk;}
Expand Down
8 changes: 5 additions & 3 deletions src/Coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ class Coin {
ZZ getSPrime() const;
ZZ getTPrime() const;

void setParameters(const BankParameters* p) { parameters = p; }

hash_t hash() const;

private:
int stat, lx, coinDenom;
const BankParameters *parameters;
const BankParameters *parameters; // NOT serialized
int walletSize; // this is W
int coinIndex; // this is J
ZZ sk_u, s, t;
ZZ sk_u, s, t; // NOT serialized
ZZ R;
hashalg_t hashAlg;
hashalg_t hashAlg; // XXX NOT serialized (??)
ZZ B, C, D; // B is commitment to sk_u, C to s, and D to t
ZZ S, T; // S = g^(1/(s+J)), T = g^(1/(t+J))
vector<ZZ> endorsement; // this is x1, x2, r_y
Expand Down
3 changes: 1 addition & 2 deletions src/FEContract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ bool FEContract::checkTimeout(int timeoutTolerance) const {
bool FEContract::checkEncAlgB(const cipher_t& encAlgR) const {
if(encAlgB != encAlgR)
throw CashException(CashException::CE_FE_ERROR,
"[FEContract::checkEncAlgB] Malformed contract (responder encryption "
"algorithm does not match)");
"[FEContract::checkEncAlgB] Malformed contract (responder encryption algorithm %s does not match %s)", encAlgR.c_str(), encAlgB.c_str());
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/FEInitiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class FEInitiator {
void setRegularPublicKey(const VEPublicKey* newpk) {regularPK = newpk;}
void setSignatureKey(Signature::Key* newsignKey = NULL)
{ delete signKey; signKey = newsignKey ? new Signature::Key(*newsignKey) : NULL; }
void setExchangeType(int et) { exchangeType = et; }

void reset();

Expand Down
6 changes: 6 additions & 0 deletions src/FESetupMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class FESetupMessage {

/*! destructor */
~FESetupMessage() { delete signPK; }

FESetupMessage(const string& s, const BankParameters *params) {
// need to set params for Coin contained in message
loadGZString(make_nvp("FESetupMessage", *this), s);
coinPrime.setParameters(params);
}

/*! check contents (verify coin and escrow) */
bool check(const VEPublicKey* pk, const int stat, const ZZ& R) const;
Expand Down
1 change: 1 addition & 0 deletions src/UserWithdrawTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class UserWithdrawTool {

ZZ getUserPublicKey() const { return userPublicKey; }
int getDenomination() const { return coinDenom; }
bool isVerified() const { return verified; }

private:
/*! creates and stores CLBlindRecipient that interacts with
Expand Down
9 changes: 8 additions & 1 deletion src/Wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ Coin Wallet::nextCoin(const ZZ &rValue) {
}

Coin* Wallet::newCoin(const ZZ &rValue, int coinIndex) {
return new Coin(params, walletSize, coinIndex, sk_u, s, t, signature, stat,
return new Coin(params, walletSize, coinIndex,
sk_u, s, t, signature, stat,
lx, rValue, coinDenom, hashAlg);
}

void Wallet::newCoin(Coin& coin, const ZZ &rValue, int coinIndex) {
coin = Coin(params, walletSize, coinIndex,
sk_u, s, t, signature, stat,
lx, rValue, coinDenom, hashAlg);
}

bool Wallet::replaceCoin(ZZ &index) {
// check that 0 <= indexArg < walletSize
if(index < 0 || index >= walletSize) {
Expand Down
9 changes: 9 additions & 0 deletions src/Wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ class Wallet {

/*! returns a coin for a given index */
Coin* newCoin(const ZZ &R, int coinIndex);
void newCoin(Coin& coin, const ZZ &R, int coinIndex);

bool replaceCoin(ZZ &index);

// some accessors
int getWalletSize() const { return walletSize; }
int getNumCoinsUsed() const { return numCoinsUsed; }
int getNumCoinsLeft() const { return walletSize - numCoinsUsed; }
int getDenomination() const { return coinDenom; }
int getRemainingValue() const { return getNumCoinsLeft() * coinDenom; }
bool empty() const { return (walletSize == numCoinsUsed); }

private:
ZZ sk_u, s, t;
int walletSize;
Expand Down

0 comments on commit e46d01a

Please sign in to comment.