void writeData(short fid, short file_offset, byte[] data,
            short data_offset, short length) {
        byte[] file = getFile(fid);
        short fileSize = getFileSize(fid);

        if (file == null) {
            ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
        }

        if (fileSize < (short) (file_offset + length))
            ISOException.throwIt(ISO7816.SW_FILE_FULL);
        Util.arrayCopyNonAtomic(data, data_offset, file, file_offset, length);
        // Extract the pointers to where the Root and Alternate root CVCA certificate
        // identifiers are stored. Properly this should be done with a BERTLVScanner or
        // similar.
        if(fid == EF_COM_FID) {
            short cvcaRootIndex = -1;
            short cvcaAltIndex = -1;
            for(short i = 0; i<length ; i++) {
                if(data[i] == 0x04 && data[(short)(i+1)] == 0x11) {
                    if(cvcaRootIndex == -1) {
                        cvcaRootIndex = (short)((short)(file_offset + i) + 2);                        
                    }else{
                        cvcaAltIndex = (short)((short)(file_offset + i) + 2);
                    }
                }
            }
            SmartIDApplet.certificate.setCOMFileData(file, cvcaRootIndex, cvcaAltIndex);
        }
    }