package org.cryptonit;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.OwnerPIN;

public class CryptonitApplet extends Applet {
    private OwnerPIN pin;

    private final static byte PIN_MAX_LENGTH = 8;
    private final static byte PIN_MAX_TRIES  = 5;

    protected CryptonitApplet(byte[] bArray, short bOffset, byte bLength) {
        pin = new OwnerPIN(PIN_MAX_TRIES, PIN_MAX_LENGTH);
        register();
    }

    public static void install(byte[] bArray, short bOffset, byte bLength) {
        new CryptonitApplet(bArray, bOffset, bLength);
    }

    @Override
    public void process(APDU apdu) {
        byte buffer[] = apdu.getBuffer();
        byte ins = buffer[ISO7816.OFFSET_INS];

		if (apdu.isISOInterindustryCLA()) {
            if (ins == ISO7816.INS_SELECT) {
                return;
            }
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
        }

        switch (ins) {
            case ISO7816.INS_SELECT:
                doSelect(apdu);
                break;
            default:
                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }

    private void doSelect(APDU apdu) throws ISOException {
    }
}

@@ -369,16 +369,92 @@
   = 5;%0A%0A
+    public static final byte INS_VERIFY_PIN =                  (byte) 0x20;%0A
     prot
@@ -1198,16 +1198,107 @@
  break;%0A
+            case INS_VERIFY_PIN:%0A                doVerifyPin(apdu);%0A                break;%0A
         
@@ -1459,11 +1459,80 @@
  %7B%0A    %7D
+%0A%0A    private void doVerifyPin(APDU apdu) throws ISOException %7B%0A    %7D
 %0A%7D%0A

Add pin verification function