com.ibm.jc
Class JCUtil

java.lang.Object
  extended bycom.ibm.jc.JCUtil

public class JCUtil
extends java.lang.Object

Various utility functions for use with an OpenPlatform/JavaCard.


Method Summary
static int arrayFill(byte[] a, int apos, int len, byte fill)
          Fills the byte array beginning at the specified position, for the specified length with the specified byte value.
static int atoi(java.lang.String str)
          Return int value of given numerical String (dec, hex, oct).
static byte[] check9000(byte[] apdu)
          Check if response APDU has status 9000.
static byte[] chop9000(byte[] apdu)
          Check if response APDU has status 9000 and chop status.
static int cmp(byte[] a, int apos, byte[] b, int bpos, int len)
          Array compare.
static short crc(byte[] buf, int off, int len)
          compute CCITT-CRC for given byte array range.
static int getMSBF(byte[] b, int pos, int n)
          Get Most Significant Byte First.
static int getStatus(byte[] apdu)
          Extract status from given response APDU.
static byte lrc(byte[] data, int off, int len)
           
static void putMSBF(int v, byte[] b, int pos, int n)
          Put Most Significant Byte First.
static short tclcrc(byte[] buf, int off, int len)
          compute ISO 14443-3 CRC for given byte array range.
static short updatecrc(short fcs, byte b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

putMSBF

public static void putMSBF(int v,
                           byte[] b,
                           int pos,
                           int n)
Put Most Significant Byte First.

Parameters:
v - Value to be written.
b - target byte array.
n - number of bytes to be written.

getMSBF

public static int getMSBF(byte[] b,
                          int pos,
                          int n)
Get Most Significant Byte First.

Parameters:
b - byte array to be read.
n - number of bytes to be read.
Returns:
the value read.

cmp

public static int cmp(byte[] a,
                      int apos,
                      byte[] b,
                      int bpos,
                      int len)
Array compare.

Parameters:
a - byte array A.
apos - offset into the A array.
bpos - offset into the B array.
len - number of bytes to be compared.
Returns:
zero if equals.

arrayFill

public static int arrayFill(byte[] a,
                            int apos,
                            int len,
                            byte fill)
Fills the byte array beginning at the specified position, for the specified length with the specified byte value.

Parameters:
a - target byte array.
apos - offset into the array where to start filling.
len - number of bytes to be filled.
fill - the byte value used for filling.
Returns:
apos+len.

getStatus

public static int getStatus(byte[] apdu)
Extract status from given response APDU.

Returns:
positive number (last two bytes of the response APDU)
Throws:
JCException - if response APDU is shorter than two bytes

check9000

public static byte[] check9000(byte[] apdu)
Check if response APDU has status 9000.

Returns:
input array for convenience
Throws:
JCException - if status is not 9000

chop9000

public static byte[] chop9000(byte[] apdu)
Check if response APDU has status 9000 and chop status.

Returns:
input array with 9000 chopped off.
Throws:
JCException - if status is not 9000

atoi

public static int atoi(java.lang.String str)
Return int value of given numerical String (dec, hex, oct). Return -1 on error.


lrc

public static byte lrc(byte[] data,
                       int off,
                       int len)

crc

public static short crc(byte[] buf,
                        int off,
                        int len)
compute CCITT-CRC for given byte array range.


tclcrc

public static short tclcrc(byte[] buf,
                           int off,
                           int len)
compute ISO 14443-3 CRC for given byte array range.


updatecrc

public static short updatecrc(short fcs,
                              byte b)