Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package testjcard;
- import javacard.framework.APDU;
- import javacard.framework.Applet;
- import javacard.framework.ISO7816;
- import javacard.framework.ISOException;
- import javacard.framework.Util;
- /**
- *
- * @author colin
- */
- public class JCardTest extends Applet {
- private byte[] echoBytes;
- private static final short LENGTH_ECHO_BYTES = 32;
- /**
- * Installs this applet.
- *
- * @param bArray
- * the array containing installation parameters
- * @param bOffset
- * the starting offset in bArray
- * @param bLength
- * the length in bytes of the parameter data in bArray
- */
- public static void install(byte[] bArray, short bOffset, byte bLength) {
- new JCardTest();
- }
- /**
- * Only this class's install method should create the applet object.
- */
- protected JCardTest() {
- echoBytes = new byte[LENGTH_ECHO_BYTES];
- register();
- }
- /**
- * Processes an incoming APDU.
- *
- * @see APDU
- * @param apdu
- * the incoming APDU
- */
- public void process(APDU apdu) {
- byte buffer[] = apdu.getBuffer();
- // check SELECT APDU command
- if ((buffer[ISO7816.OFFSET_CLA] == 0) &&
- (buffer[ISO7816.OFFSET_INS] == (byte) (0xA4))) {
- return;
- }
- short bytesRead = apdu.setIncomingAndReceive();
- //short echoOffset = (short) 0;
- short outerLoopCounter = 0;
- short innerLoopCounter = 0;
- short iterations = (short) 0;
- while (bytesRead > 0) {
- //Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
- //echoOffset += bytesRead;
- bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
- }
- for(outerLoopCounter=0;outerLoopCounter<2;outerLoopCounter++){
- for(innerLoopCounter=0;innerLoopCounter<1000;innerLoopCounter++){
- iterations = (short) (iterations + (short)1);
- }
- }
- //Map to bytes
- echoBytes[0] = (byte)(outerLoopCounter >> 8);
- echoBytes[1] = (byte)outerLoopCounter;
- echoBytes[2] = (byte)(innerLoopCounter >> 8);
- echoBytes[3] = (byte)innerLoopCounter;
- echoBytes[4] = (byte)(iterations >> 8);
- echoBytes[5] = (byte)iterations;
- apdu.setOutgoing();
- apdu.setOutgoingLength((short) (6 + 5));
- // echo header
- apdu.sendBytes((short) 0, (short) 5);
- // echo data
- apdu.sendBytesLong(echoBytes, (short) 0, (short) 6);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment