1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-08 23:37:47 +02:00

scd: Add function for binary read in extended mode.

* scd/iso7816.c (iso7816_read_binary): Factor code out to ...
(iso7816_read_binary_ext): new function.  Add arg extended_mode.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-03-31 11:53:36 +02:00
parent c29603fa9a
commit c9ad81070a
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 17 additions and 4 deletions

View File

@ -825,8 +825,9 @@ iso7816_get_challenge (int slot, int length, unsigned char *buffer)
stored in a newly allocated buffer at the address passed by RESULT. stored in a newly allocated buffer at the address passed by RESULT.
Returns the length of this data at the address of RESULTLEN. */ Returns the length of this data at the address of RESULTLEN. */
gpg_error_t gpg_error_t
iso7816_read_binary (int slot, size_t offset, size_t nmax, iso7816_read_binary_ext (int slot, int extended_mode,
unsigned char **result, size_t *resultlen) size_t offset, size_t nmax,
unsigned char **result, size_t *resultlen)
{ {
int sw; int sw;
unsigned char *buffer; unsigned char *buffer;
@ -849,13 +850,13 @@ iso7816_read_binary (int slot, size_t offset, size_t nmax,
buffer = NULL; buffer = NULL;
bufferlen = 0; bufferlen = 0;
n = read_all? 0 : nmax; n = read_all? 0 : nmax;
sw = apdu_send_le (slot, 0, 0x00, CMD_READ_BINARY, sw = apdu_send_le (slot, extended_mode, 0x00, CMD_READ_BINARY,
((offset>>8) & 0xff), (offset & 0xff) , -1, NULL, ((offset>>8) & 0xff), (offset & 0xff) , -1, NULL,
n, &buffer, &bufferlen); n, &buffer, &bufferlen);
if ( SW_EXACT_LENGTH_P(sw) ) if ( SW_EXACT_LENGTH_P(sw) )
{ {
n = (sw & 0x00ff); n = (sw & 0x00ff);
sw = apdu_send_le (slot, 0, 0x00, CMD_READ_BINARY, sw = apdu_send_le (slot, extended_mode, 0x00, CMD_READ_BINARY,
((offset>>8) & 0xff), (offset & 0xff) , -1, NULL, ((offset>>8) & 0xff), (offset & 0xff) , -1, NULL,
n, &buffer, &bufferlen); n, &buffer, &bufferlen);
} }
@ -914,6 +915,15 @@ iso7816_read_binary (int slot, size_t offset, size_t nmax,
return 0; return 0;
} }
gpg_error_t
iso7816_read_binary (int slot, size_t offset, size_t nmax,
unsigned char **result, size_t *resultlen)
{
return iso7816_read_binary_ext (slot, 0, offset, nmax, result, resultlen);
}
/* Perform a READ RECORD command. RECNO gives the record number to /* Perform a READ RECORD command. RECNO gives the record number to
read with 0 indicating the current record. RECCOUNT must be 1 (not read with 0 indicating the current record. RECCOUNT must be 1 (not
all cards support reading of more than one record). SHORT_EF all cards support reading of more than one record). SHORT_EF

View File

@ -129,6 +129,9 @@ gpg_error_t iso7816_read_public_key (int slot, int extended_mode,
gpg_error_t iso7816_get_challenge (int slot, gpg_error_t iso7816_get_challenge (int slot,
int length, unsigned char *buffer); int length, unsigned char *buffer);
gpg_error_t iso7816_read_binary_ext (int slot, int extended_mode,
size_t offset, size_t nmax,
unsigned char **result, size_t *resultlen);
gpg_error_t iso7816_read_binary (int slot, size_t offset, size_t nmax, gpg_error_t iso7816_read_binary (int slot, size_t offset, size_t nmax,
unsigned char **result, size_t *resultlen); unsigned char **result, size_t *resultlen);
gpg_error_t iso7816_read_record (int slot, int recno, int reccount, gpg_error_t iso7816_read_record (int slot, int recno, int reccount,