FileDocCategorySizeDatePackage
SecurePurseImpl.javaAPI DocJava Card3409Wed Mar 22 21:07:24 GMT 2006com.sun.javacard.samples.SecureRMIDemo

SecurePurseImpl

public class SecurePurseImpl extends javacard.framework.service.CardRemoteObject implements Purse

Fields Summary
private short
balance
private byte[]
number
private javacard.framework.service.SecurityService
security
Constructors Summary
public SecurePurseImpl(javacard.framework.service.SecurityService security)

    
    
       
        super();                     // export it
        this.security = security;
        number = new byte[5];
    
Methods Summary
public voidcredit(short m)

        
        if( !security.isCommandSecure(SecurityService.PROPERTY_INPUT_INTEGRITY)){
            UserException.throwIt(CORRUPTED_DATA);
        }
            
        if(!security.isAuthenticated(SecurityService.PRINCIPAL_APP_PROVIDER)) {
            UserException.throwIt(REQUEST_DENIED);
        }
        
        
        
        if(m<=0) UserException.throwIt(BAD_ARGUMENT);
        
        if((short)(balance+m) > MAX_AMOUNT) UserException.throwIt(OVERFLOW);
        
        balance +=m;
    
public voiddebit(short m)

        
        if( !security.isCommandSecure(SecurityService.PROPERTY_INPUT_INTEGRITY)){
            UserException.throwIt(CORRUPTED_DATA);
        }
            
        if(!security.isAuthenticated(SecurityService.PRINCIPAL_CARDHOLDER)) {
            UserException.throwIt(REQUEST_DENIED);
        }
        
        
        if(m<=0) UserException.throwIt(BAD_ARGUMENT);
        
        if((short)(balance-m) < 0) UserException.throwIt(UNDERFLOW);
        
        balance -=m;
    
public byte[]getAccountNumber()

        
        if( !security.isCommandSecure(SecurityService.PROPERTY_INPUT_INTEGRITY)){
            UserException.throwIt(CORRUPTED_DATA);
        }
            
        if(!security.isAuthenticated(SecurityService.PRINCIPAL_CARDHOLDER)) {
            UserException.throwIt(REQUEST_DENIED);
        }
        
        
        return number;
    
public shortgetBalance()

        
        if( !security.isCommandSecure(SecurityService.PROPERTY_INPUT_INTEGRITY)){
            UserException.throwIt(CORRUPTED_DATA);
        }
            
        if(!security.isAuthenticated(SecurityService.PRINCIPAL_APP_PROVIDER)) {
            UserException.throwIt(REQUEST_DENIED);
        }
        
        
        return balance;
    
public voidsetAccountNumber(byte[] number)

        
        if( !security.isCommandSecure(SecurityService.PROPERTY_INPUT_INTEGRITY)){
            UserException.throwIt(CORRUPTED_DATA);
        }
            
        if(!security.isAuthenticated(SecurityService.PRINCIPAL_APP_PROVIDER)) {
            UserException.throwIt(REQUEST_DENIED);
        }
        
        
        
        
        if(number.length != 5) UserException.throwIt(BAD_ARGUMENT);
        Util.arrayCopy(number, (short)0, this.number, (short)0, (short)5);