sc_*_binary: interpret SC_SUCCESS as EOF

This commit is contained in:
Frank Morgner 2020-01-31 14:47:45 +01:00
parent 167c03fde4
commit ad8b9f5034
5 changed files with 23 additions and 60 deletions

View File

@ -621,15 +621,6 @@ done:
LOG_FUNC_RETURN(card->ctx, r);
}
/* CAC driver is read only */
static int cac_write_binary(sc_card_t *card, unsigned int idx,
const u8 *buf, size_t count, unsigned long flags)
{
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
}
/* initialize getting a list and return the number of elements in the list */
static int cac_get_init_and_get_count(list_t *list, cac_object_t **entry, int *countp)
{
@ -1910,7 +1901,8 @@ static struct sc_card_driver * sc_get_driver(void)
cac_ops.select_file = cac_select_file; /* need to record object type */
cac_ops.get_challenge = cac_get_challenge;
cac_ops.read_binary = cac_read_binary;
cac_ops.write_binary = cac_write_binary;
/* CAC driver is read only */
cac_ops.write_binary = NULL;
cac_ops.set_security_env = cac_set_security_env;
cac_ops.restore_security_env = cac_restore_security_env;
cac_ops.compute_signature = cac_compute_signature;

View File

@ -206,20 +206,6 @@ jpki_select_file(struct sc_card *card,
LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
}
static int
jpki_read_binary(sc_card_t * card, unsigned int idx,
u8 * buf, size_t count, unsigned long flags)
{
struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
const struct sc_card_operations *iso_ops = iso_drv->ops;
int rc;
LOG_FUNC_CALLED(card->ctx);
rc = iso_ops->read_binary(card, idx, buf, count, flags);
LOG_FUNC_RETURN(card->ctx, rc);
}
static int
jpki_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data, int *tries_left)
{
@ -385,7 +371,6 @@ sc_get_driver(void)
jpki_ops.init = jpki_init;
jpki_ops.finish = jpki_finish;
jpki_ops.select_file = jpki_select_file;
jpki_ops.read_binary = jpki_read_binary;
jpki_ops.pin_cmd = jpki_pin_cmd;
jpki_ops.set_security_env = jpki_set_security_env;
jpki_ops.compute_signature = jpki_compute_signature;

View File

@ -1617,17 +1617,6 @@ pgp_read_binary(sc_card_t *card, unsigned int idx,
}
/**
* ABI: ISO 7816-4 WRITE BINARY - write data to currently selected EF.
*/
static int
pgp_write_binary(sc_card_t *card, unsigned int idx,
const u8 *buf, size_t count, unsigned long flags)
{
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
}
/**
* Internal: get public key from card - as DF + sub-wEFs.
*/
@ -3574,7 +3563,7 @@ sc_get_openpgp_driver(void)
pgp_ops.list_files = pgp_list_files;
pgp_ops.get_challenge = pgp_get_challenge;
pgp_ops.read_binary = pgp_read_binary;
pgp_ops.write_binary = pgp_write_binary;
pgp_ops.write_binary = NULL;
pgp_ops.pin_cmd = pgp_pin_cmd;
pgp_ops.logout = pgp_logout;
pgp_ops.get_data = pgp_get_data;

View File

@ -650,9 +650,8 @@ int sc_read_binary(sc_card_t *card, unsigned int idx,
size_t chunk = todo > max_le ? max_le : todo;
r = card->ops->read_binary(card, idx, buf, chunk, flags);
if (r == SC_SUCCESS) {
r = (int) chunk;
}
if (r == 0 || r = SC_ERROR_FILE_END_REACHED)
break;
if ((idx > SIZE_MAX - (size_t) r)
|| (size_t) r > todo) {
/* `idx + r` or `todo - r` would overflow */
@ -670,7 +669,7 @@ int sc_read_binary(sc_card_t *card, unsigned int idx,
sc_unlock(card);
LOG_FUNC_RETURN(card->ctx, count);
LOG_FUNC_RETURN(card->ctx, count - todo);
}
int sc_write_binary(sc_card_t *card, unsigned int idx,
@ -699,9 +698,8 @@ int sc_write_binary(sc_card_t *card, unsigned int idx,
size_t chunk = todo > max_lc ? max_lc : todo;
r = card->ops->write_binary(card, idx, buf, chunk, flags);
if (r == SC_SUCCESS) {
r = (int) chunk;
}
if (r == 0 || r = SC_ERROR_FILE_END_REACHED)
break;
if ((idx > SIZE_MAX - (size_t) r)
|| (size_t) r > todo) {
/* `idx + r` or `todo - r` would overflow */
@ -719,7 +717,7 @@ int sc_write_binary(sc_card_t *card, unsigned int idx,
sc_unlock(card);
LOG_FUNC_RETURN(card->ctx, count);
LOG_FUNC_RETURN(card->ctx, count - todo);
}
int sc_update_binary(sc_card_t *card, unsigned int idx,
@ -756,9 +754,8 @@ int sc_update_binary(sc_card_t *card, unsigned int idx,
size_t chunk = todo > max_lc ? max_lc : todo;
r = card->ops->update_binary(card, idx, buf, chunk, flags);
if (r == SC_SUCCESS) {
r = (int) chunk;
}
if (r == 0 || r = SC_ERROR_FILE_END_REACHED)
break;
if ((idx > SIZE_MAX - (size_t) r)
|| (size_t) r > todo) {
/* `idx + r` or `todo - r` would overflow */
@ -776,7 +773,7 @@ int sc_update_binary(sc_card_t *card, unsigned int idx,
sc_unlock(card);
LOG_FUNC_RETURN(card->ctx, count);
LOG_FUNC_RETURN(card->ctx, count - todo);
}
@ -803,8 +800,12 @@ int sc_erase_binary(struct sc_card *card, unsigned int idx, size_t count, unsig
while (todo > 0) {
r = card->ops->erase_binary(card, idx, todo, flags);
if (r == SC_SUCCESS) {
r = todo;
if (r == 0 || r = SC_ERROR_FILE_END_REACHED)
break;
if ((idx > SIZE_MAX - (size_t) r)
|| (size_t) r > todo) {
/* `idx + r` or `todo - r` would overflow */
r = SC_ERROR_OFFSET_TOO_LARGE;
}
if (r < 0) {
sc_unlock(card);
@ -817,7 +818,7 @@ int sc_erase_binary(struct sc_card *card, unsigned int idx, size_t count, unsig
sc_unlock(card);
LOG_FUNC_RETURN(card->ctx, count);
LOG_FUNC_RETURN(card->ctx, count - todo);
}

View File

@ -638,8 +638,7 @@ struct sc_card_operations {
* @param buf buffer to the read data
* @param count number of bytes to read
* @param flags flags for the READ BINARY command (currently not used)
* @return number of bytes read or an error code.
* SC_SUCCESS indicates that all requested bytes were read.
* @return number of bytes read or an error code
*
* @see sc_read_binary()
*/
@ -655,8 +654,7 @@ struct sc_card_operations {
* @param buf buffer with the data
* @param count number of bytes to write
* @param flags flags for the WRITE BINARY command (currently not used)
* @return number of bytes written or an error code.
* SC_SUCCESS indicates that all requested bytes were written.
* @return number of bytes written or an error code
*
* @see sc_write_binary()
*/
@ -671,8 +669,7 @@ struct sc_card_operations {
* @param buf buffer with the new data
* @param count number of bytes to update
* @param flags flags for the UPDATE BINARY command (currently not used)
* @return number of bytes written or an error code.
* SC_SUCCESS indicates that all requested bytes were updated.
* @return number of bytes written or an error code
*
* @see sc_update_binary()
*/
@ -687,8 +684,7 @@ struct sc_card_operations {
* @param idx index within the file for the data to be erased
* @param count number of bytes to erase
* @param flags flags for the ERASE BINARY command (currently not used)
* @return number of bytes erased or an error code.
* SC_SUCCESS indicates that all requested bytes were erased.
* @return number of bytes erased or an error code
*
* @see sc_erase_binary()
*/