OpenPGP: clean up & fix pgp_delete_file()

* use LOG_FUNC_CALLED() .. LOG_FUNC_RETURN for "symmetric" logging
* don't zero-fill the DO's contents but empty it
* get rid of unnecessary variables
* select parent DF after deletion (required by to ISO 7816-9)
* don't try to delete MF
This commit is contained in:
Peter Marschall 2012-06-07 20:31:44 +02:00
parent 2aa4cf57ed
commit a09f304817
1 changed files with 18 additions and 22 deletions

View File

@ -1509,42 +1509,38 @@ static int pgp_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
}
/* ABI: Delete file */
static int pgp_delete_file(sc_card_t *card, const sc_path_t *path)
/* ABI: DELETE FILE */
static int
pgp_delete_file(sc_card_t *card, const sc_path_t *path)
{
struct pgp_priv_data *priv = DRVDATA(card);
struct blob *blob;
sc_file_t *file;
struct blob *affected_blob;
u8 *data;
size_t len;
int r;
LOG_FUNC_CALLED(card->ctx);
/* In sc_pkcs15init_delete_by_path(), the path type was set to SC_PATH_TYPE_FILE_ID */
/* In sc_pkcs15init_delete_by_path(), the path type was set to SC_PATH_TYPE_FILE_ID */
r = pgp_select_file(card, path, &file);
LOG_TEST_RET(card->ctx, r, "Cannot select file.");
affected_blob = priv->current;
len = affected_blob->len;
/* Create zero-filled buffer to put to DO.
* Though the spec says that PUT DATA with Lc=0 can erase the DO,
* but this format of APDU is not allowed by OpenSC and in fact,
* my CryptoStick responds "64 00" (execution error).
* So, to erase DO, we will put all zeros to it. */
data = malloc(affected_blob->len);
if (data == NULL)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
memset(data, 0, len);
/* save "current" blob */
blob = priv->current;
r = pgp_put_data(card, file->id, data, len);
if (r < 0)
sc_log(card->ctx, "Failed to erase %04X DO: %s", file->id, sc_strerror(r));
/* do try to delete MF */
if (blob == priv->mf)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
free(data);
return r;
/* call pgp_put_data() with zero-sized NULL-buffer to zap the DO contents */
r = pgp_put_data(card, file->id, NULL, 0);
/* set "current" blob to parent */
priv->current = blob->parent;
LOG_FUNC_RETURN(card->ctx, r);
}
/* ABI: UPDATE BINARY */
static int
pgp_update_binary(sc_card_t *card, unsigned int idx,