Methods Summary |
---|
private void | credit(APDU apdu)
byte[] buffer = apdu.getBuffer();
byte numBytes = buffer[ISO7816.OFFSET_LC];
byte byteRead = (byte)(apdu.setIncomingAndReceive());
if ( ( numBytes != 2 ) || (byteRead != 2) )
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
short creditAmount = (short)
((short)(buffer[ISO7816.OFFSET_CDATA] << (short)8) |
(short)(buffer[ISO7816.OFFSET_CDATA + 1]));
if ( ( creditAmount > MAX_BALANCE)
|| ( creditAmount < (short)0 ) ) {
ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
}
if ( (short)( balance + creditAmount) > MAX_BALANCE ) {
ISOException.throwIt(SW_MAX_BALANCE_EXCEEDED);
}
JCSystem.beginTransaction();
balance = (short)(balance + creditAmount);
JCSystem.commitTransaction();
|
boolean | debit(short areaCode, boolean contactless)
short amtToDebit;
if (areaCode == homeArea) {
amtToDebit = chargeRate[AREA_HOME];
} else {
amtToDebit = chargeRate[AREA_REMOTE];
}
//charge more if contactless
if(contactless)
amtToDebit += 20;
if (balance >= amtToDebit) {
JCSystem.beginTransaction();
balance = (short)(balance - amtToDebit);
JCSystem.commitTransaction();
return true;
} else {
return false;
}
|
public void | deselect()
// Nothing to do
|
public void | deselect(boolean appInstStillSelected)
// Nothing to do
|
public static com.sun.javacard.samples.ChannelsDemo.AccountAccessor | getAccount()
return theAccount;
|
private void | getBalance(APDU apdu)
AID connection_aid = JCSystem.lookupAID( CONNECTION_MGR_AID_BYTES,
(short)0, (byte)CONNECTION_MGR_AID_BYTES.length);
if (!(JCSystem.isAppletActive(connection_aid)))
ISOException.throwIt(SW_NO_CONNECTION);
byte[] buffer = apdu.getBuffer();
short le = apdu.setOutgoing();
if ( le < 2 )
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoingLength((byte)2);
buffer[0] = (byte)(balance >> (short)8);
buffer[1] = (byte)(balance & (short)0x00FF);
apdu.sendBytes((short)0, (short)2);
|
public static void | install(byte[] bArray, short bOffset, byte bLength)
new AccountAccessor(bArray, bOffset, bLength);
|
public void | process(APDU apdu)
byte[] buffer = apdu.getBuffer();
if (apdu.isISOInterindustryCLA()) {
if (buffer[ISO7816.OFFSET_INS] == (byte)(0xA4)) {
return;
} else {
ISOException.throwIt (ISO7816.SW_CLA_NOT_SUPPORTED);
}
}
switch (buffer[ISO7816.OFFSET_INS]) {
case GET_BALANCE:
getBalance(apdu);
return;
case CREDIT:
credit(apdu);
return;
default:
ISOException.throwIt (ISO7816.SW_INS_NOT_SUPPORTED);
}
|
public boolean | select()
return true;
|
public boolean | select(boolean appInstAlreadySelected)
return true;
|