Java Code Examples for javacard.framework.JCSystem#makeTransientShortArray()

The following examples show how to use javacard.framework.JCSystem#makeTransientShortArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NdefApplet.java    From openjavacard-ndef with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Main constructor
 *
 * This will construct and initialize an instance
 * of this applet according to the provided app data.
 *
 * @param buf containing application data
 * @param off offset of app data in buf
 * @param len length of app data in buf
 */
protected NdefApplet(byte[] buf, short off, byte len) {
    // length of actual data file
    short dataLen = (short)(len + 2);
    // create transient variables
    vars = JCSystem.makeTransientShortArray(NUM_VARS, JCSystem.CLEAR_ON_DESELECT);
    // create capabilities files
    capsFile = makeCaps(dataLen);
    // create data file
    byte[] data = null;
    if (len > 0) {
        data = new byte[dataLen];
        // container size
        Util.setShort(data, (short) 0, len);
        // initial data
        Util.arrayCopyNonAtomic(buf, off, data, (short) 2, len);
    } else {
        ISOException.throwIt(ISO7816.SW_DATA_INVALID);
    }
    dataFile = data;
}
 
Example 2
Source File: NdefApplet.java    From openjavacard-ndef with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Main constructor
 *
 * This will construct and initialize an instance
 * of this applet according to the provided app data.
 *
 * @param buf containing application data
 * @param off offset of app data in buf
 * @param len length of app data in buf
 */
protected NdefApplet(byte[] buf, short off, byte len) {
    // create transient variables
    vars = JCSystem.makeTransientShortArray(NUM_VARS, JCSystem.CLEAR_ON_DESELECT);
    refs = JCSystem.makeTransientObjectArray(NUM_REFS, JCSystem.CLEAR_ON_DESELECT);
    // create capabilities files
    capsFile = makeCaps((short)0);
    // process install data
    if(len < 6 || len > 17) {
        ISOException.throwIt(ISO7816.SW_WRONG_DATA);
    }
    // first byte is the service ID
    serviceID = buf[off++]; len--;
    // rest is the service AID
    serviceAID = new byte[len];
    Util.arrayCopyNonAtomic(buf, off, serviceAID, (short)0, len);
}
 
Example 3
Source File: SHA512.java    From ledger-javacard with GNU Affero General Public License v3.0 5 votes vote down vote up
public SHA512() {
  working = JCSystem.makeTransientShortArray((short)(2 + 8*4
                                                       ),
                                               JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT);
  blk = JCSystem.makeTransientShortArray((short)(64),
                                               JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT);
  init();
}
 
Example 4
Source File: TransmitManager.java    From GidsApplet with GNU General Public License v3.0 4 votes vote down vote up
public TransmitManager() {
    ram_buf = JCSystem.makeTransientByteArray(RAM_BUF_SIZE, JCSystem.CLEAR_ON_DESELECT);
    chaining_cache = JCSystem.makeTransientShortArray(CHAINING_CACHE_SIZE, JCSystem.CLEAR_ON_DESELECT);
    chaining_object = JCSystem.makeTransientObjectArray((short) 2, JCSystem.CLEAR_ON_DESELECT);

}
 
Example 5
Source File: NdefApplet.java    From openjavacard-ndef with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Main constructor
 *
 * This will construct and initialize an instance
 * of this applet according to the provided app data.
 *
 * @param buf containing application data
 * @param off offset of app data in buf
 * @param len length of app data in buf
 */
protected NdefApplet(byte[] buf, short off, byte len) {

    short initSize = DEFAULT_NDEF_DATA_SIZE;
    byte initReadAccess = DEFAULT_NDEF_READ_ACCESS;
    byte initWriteAccess = DEFAULT_NDEF_WRITE_ACCESS;
    byte[] initBuf = null;
    short  initOff = 0;
    short  initLen = 0;

    // create variables
    vars = JCSystem.makeTransientShortArray(NUM_VARS, JCSystem.CLEAR_ON_DESELECT);

    // process application data
    if(FEATURE_INSTALL_PARAMETERS) {
        // check TLV consistency
        if (!UtilTLV.isTLVconsistent(buf, off, len)) {
            ISOException.throwIt(ISO7816.SW_DATA_INVALID);
        }

        // DATA INITIAL
        short initTag = UtilTLV.findTag(buf, off, len, AD_TAG_NDEF_DATA_INITIAL);
        if (initTag >= 0) {
            initBuf = buf;
            initLen = UtilTLV.decodeLengthField(buf, (short) (initTag + 1));
            initOff = (short) (initTag + 1 + UtilTLV.getLengthFieldLength(initLen));
            // restrict writing, can be overridden using DATA ACCESS
            initWriteAccess = FILE_ACCESS_NONE;
            // adjust size, can be overridden
            initSize = (short) (2 + initLen);
        }

        // DATA ACCESS
        short tagAccess = UtilTLV.findTag(buf, off, len, AD_TAG_NDEF_DATA_ACCESS);
        if (tagAccess >= 0) {
            short accessLen = UtilTLV.decodeLengthField(buf, (short) (tagAccess + 1));
            if (accessLen != 2) {
                ISOException.throwIt(ISO7816.SW_DATA_INVALID);
            }
            initReadAccess = buf[(short) (tagAccess + 2)];
            initWriteAccess = buf[(short) (tagAccess + 3)];
        }

        // DATA SIZE
        short tagSize = UtilTLV.findTag(buf, off, len, AD_TAG_NDEF_DATA_SIZE);
        if (tagSize >= 0) {
            short sizeLen = UtilTLV.decodeLengthField(buf, (short) (tagSize + 1));
            if (sizeLen != 2) {
                ISOException.throwIt(ISO7816.SW_DATA_INVALID);
            }
            initSize = Util.getShort(buf, (short) (tagSize + 2));
            if (initSize < 0) {
                ISOException.throwIt(ISO7816.SW_DATA_INVALID);
            }
        }
    }

    // squash write access if not supported
    if(!FEATURE_WRITING) {
        initWriteAccess = FILE_ACCESS_NONE;
    }

    // set up access
    dataReadAccess = initReadAccess;
    dataWriteAccess = initWriteAccess;

    // create file contents
    capsFile = makeCaps(initSize, initReadAccess, initWriteAccess);
    dataFile = makeData(initSize, initBuf, initOff, initLen);
}
 
Example 6
Source File: Transaction.java    From SatochipApplet with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void init() {
    ctx = JCSystem.makeTransientByteArray(TX_CONTEXT_SIZE, JCSystem.CLEAR_ON_DESELECT);
    ctx2 = JCSystem.makeTransientShortArray((short)3, JCSystem.CLEAR_ON_DESELECT);
    digestFull = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false);
}
 
Example 7
Source File: Transaction.java    From ledger-javacard with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void init() {
    h = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
}
 
Example 8
Source File: BCDUtils.java    From ledger-javacard with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void init() {
    scratch = JCSystem.makeTransientShortArray((short)(8 * 8 / 3), JCSystem.CLEAR_ON_DESELECT);
}