0% found this document useful (0 votes)
8 views2 pages

R W

This document contains the code for a Java Card applet. It defines constants for message types, a non-volatile memory array, and install and process methods. The process method handles different instructions by checking the instruction code, performing operations like reading from and writing to non-volatile memory, and returning response messages. It includes code to validate parameters and return error codes if validation fails.

Uploaded by

Slimen Zeineb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

R W

This document contains the code for a Java Card applet. It defines constants for message types, a non-volatile memory array, and install and process methods. The process method handles different instructions by checking the instruction code, performing operations like reading from and writing to non-volatile memory, and returning response messages. It includes code to validate parameters and return error codes if validation fails.

Uploaded by

Slimen Zeineb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package pkgname;

import javacard.framework.*;

public class AppletName extends javacard.framework.Applet{


private static final byte[] assurance = { //
(byte) 0x48, //
(byte) 0x65, //
(byte) 0x6c, //
(byte) 0x6c, //
(byte) 0x6f, //
};
final static byte affichage = (byte) 0x01 ;
final static byte BINARY_WRITE = (byte) 0x02 ;
final static byte BINARY_READ = (byte) 0x03 ;

final static short NVRSIZE = (short) 500;


static byte[] NVR = new byte[NVRSIZE] ;

public static void install(byte[] bArray, short bOffset, byte bLength){


(new AppletName()).register(bArray, (short)(bOffset + 1),
bArray[bOffset]);
}

public void process(APDU apdu){

short adr,len;
byte[] buffer = apdu.getBuffer() ;

if (this.selectingApplet()) return;
// lecture CLA INS P1 P2 P3

byte ins = buffer[ISO7816.OFFSET_INS];


byte P1 = buffer[ISO7816.OFFSET_P1] ;
byte P2 = buffer[ISO7816.OFFSET_P2] ;
byte P3 = buffer[ISO7816.OFFSET_LC] ;
adr = Util.makeShort(P1,P2) ;
len = Util.makeShort((byte)0,P3) ;

if (buffer[ISO7816.OFFSET_CLA] != 0xf0) {

ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
switch (ins) {
case affichage:
Util.arrayCopy(assurance, (short) 0, buffer, (short) 0, (short)
assurance.length);
apdu.setOutgoingAndSend((short) 0, (short) assurance.length);
return;

case BINARY_READ:
// Question 1: test si adr <0 et Retourne le status word CLA WRONG_LENGTH
if (adr < (short)0)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH) ;
// Question 2: test si adr + len) >NVRSIZE et Retourne le status word
WRONG_LENGTH
if ((short)(adr + len) > (short)NVRSIZE)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH) ;
// Question 3 R�alise des transferts de m�moire � m�moire et
// transmet un message de r�ponse contenu dans le tampon de
r�ception
Util.arrayCopy(NVR,adr,buffer,(short)0,len);
apdu.setOutgoingAndSend((short)0,len);
break;

case BINARY_WRITE:
short readCount = apdu.setIncomingAndReceive(); //
offset=5 ...
// Question 4: test si readCount <0 et Retourne le status word
WRONG_LENGTH
if (readCount <= 0)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH) ;
if (adr < (short)0)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH) ;
if ((short)(adr + len) > (short)NVRSIZE )
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH) ;
// Question 5: �criture par copie de l�apdu de commande
Util.arrayCopy(buffer,(short)5,NVR,adr,len);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}}

You might also like