Skip to content

Commit

Permalink
emv_pk: fix endianness in dumping functions
Browse files Browse the repository at this point in the history
Dumping functions incorrectly used unsigned char instead of char
strings.

Signed-off-by: Dmitry Eremin-Solenikov <[email protected]>
  • Loading branch information
lumag committed Nov 13, 2015
1 parent 9605ce3 commit 0566cae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/emv_pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct emv_pk *emv_pk_parse_pk(char *buf)
return NULL;
}

static size_t emv_pk_write_bin(unsigned char *out, size_t outlen, const unsigned char *buf, size_t len)
static size_t emv_pk_write_bin(char *out, size_t outlen, const unsigned char *buf, size_t len)
{
int i;
size_t pos = 0;
Expand All @@ -227,7 +227,7 @@ static size_t emv_pk_write_bin(unsigned char *out, size_t outlen, const unsigned
return pos;
}

static size_t emv_pk_write_str(unsigned char *out, size_t outlen, const char *str)
static size_t emv_pk_write_str(char *out, size_t outlen, const char *str)
{
size_t len = strlen(str);

Expand All @@ -241,10 +241,10 @@ static size_t emv_pk_write_str(unsigned char *out, size_t outlen, const char *st
return len;
}

unsigned char *emv_pk_dump_pk(const struct emv_pk *pk)
char *emv_pk_dump_pk(const struct emv_pk *pk)
{
size_t outsize = 1024; /* should be enough */
unsigned char *out = malloc(outsize); /* should be enough */
char *out = malloc(outsize); /* should be enough */
size_t outpos = 0;
size_t rc;

Expand Down
2 changes: 1 addition & 1 deletion lib/include/openemv/emv_pk.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct emv_pk {
struct emv_pk *emv_pk_parse_pk(char *buf);
struct emv_pk *emv_pk_new(size_t modlen, size_t explen);
void emv_pk_free(struct emv_pk *pk);
unsigned char *emv_pk_dump_pk(const struct emv_pk *pk);
char *emv_pk_dump_pk(const struct emv_pk *pk);
bool emv_pk_verify(const struct emv_pk *pk);

struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx);
Expand Down
3 changes: 1 addition & 2 deletions test/capk-verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ int main(int argc, char **argv) {
if (emv_pk_verify(pk)) {
fprintf(stderr, "OK\n");
if (argc > 2 && argv[2][0] == 'v') {
unsigned char *c;
c = emv_pk_dump_pk(pk);
char *c = emv_pk_dump_pk(pk);
if (c)
printf("%s\n", c);
free(c);
Expand Down

0 comments on commit 0566cae

Please sign in to comment.