Search in sources :

Example 1 with SelectFileApduResponse

use of es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse in project jmulticard by ctt-gob-es.

the class Iso7816FourCard method selectFileById.

/**
 * Selecciona un fichero (DF o EF).
 * @param id Identificador del fichero a seleccionar.
 * @return Tamaño del fichero seleccionado.
 * @throws ApduConnectionException Si hay problemas en el envío de la APDU.
 * @throws Iso7816FourCardException Si falla la selección de fichero.
 */
public int selectFileById(final byte[] id) throws ApduConnectionException, Iso7816FourCardException {
    final CommandApdu selectCommand = new SelectFileByIdApduCommand(getCla(), id);
    final ResponseApdu res = getConnection().transmit(selectCommand);
    if (HexUtils.arrayEquals(res.getBytes(), new byte[] { (byte) 0x6a, (byte) 0x82 })) {
        throw new FileNotFoundException(id);
    }
    final SelectFileApduResponse response = new SelectFileApduResponse(res);
    if (response.isOk()) {
        return response.getFileLength();
    }
    final StatusWord sw = response.getStatusWord();
    if (sw.equals(new StatusWord((byte) 0x6A, (byte) 0x82))) {
        throw new FileNotFoundException(id);
    }
    throw new Iso7816FourCardException(sw, selectCommand);
}
Also used : SelectFileByIdApduCommand(es.gob.jmulticard.apdu.iso7816four.SelectFileByIdApduCommand) SelectFileApduResponse(es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) StatusWord(es.gob.jmulticard.apdu.StatusWord) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Example 2 with SelectFileApduResponse

use of es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse in project jmulticard by ctt-gob-es.

the class SmartCafePkcs15Applet method selectFileById.

/**
 * Selecciona un fichero (DF o EF).
 * @param id Identificador del fichero a seleccionar.
 * @return Tamaño del fichero seleccionado.
 * @throws ApduConnectionException Si hay problemas en el envío de la APDU.
 * @throws Iso7816FourCardException Si falla la selección de fichero.
 */
@Override
public int selectFileById(final byte[] id) throws ApduConnectionException, Iso7816FourCardException {
    final CommandApdu selectCommand = new SelectFileByIdApduCommand(getCla(), id);
    final ResponseApdu res = getConnection().transmit(selectCommand);
    if (HexUtils.arrayEquals(res.getBytes(), new byte[] { (byte) 0x6a, (byte) 0x82 })) {
        throw new FileNotFoundException(id);
    }
    final SelectFileApduResponse response = new SelectFileApduResponse(res);
    if (response.isOk()) {
        return HexUtils.getUnsignedInt(new byte[] { response.getData()[4], response.getData()[5] }, // Offset
        0);
    }
    final StatusWord sw = response.getStatusWord();
    if (sw.equals(new StatusWord((byte) 0x6A, (byte) 0x82))) {
        throw new FileNotFoundException(id);
    }
    throw new Iso7816FourCardException(sw, selectCommand);
}
Also used : SelectFileByIdApduCommand(es.gob.jmulticard.apdu.iso7816four.SelectFileByIdApduCommand) SelectFileApduResponse(es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse) Iso7816FourCardException(es.gob.jmulticard.card.iso7816four.Iso7816FourCardException) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) StatusWord(es.gob.jmulticard.apdu.StatusWord) FileNotFoundException(es.gob.jmulticard.card.iso7816four.FileNotFoundException) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Aggregations

CommandApdu (es.gob.jmulticard.apdu.CommandApdu)2 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)2 StatusWord (es.gob.jmulticard.apdu.StatusWord)2 SelectFileApduResponse (es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse)2 SelectFileByIdApduCommand (es.gob.jmulticard.apdu.iso7816four.SelectFileByIdApduCommand)2 FileNotFoundException (es.gob.jmulticard.card.iso7816four.FileNotFoundException)1 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)1