summary: - add new function sc_format_oid to libopensc
- cleanup libopensc api git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2670 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
89cfac8735
commit
fa65fbf285
|
@ -2,6 +2,7 @@
|
|||
* internal.h: Internal definitions for libopensc
|
||||
*
|
||||
* Copyright (C) 2001, 2002 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* 2005 The OpenSC project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -88,6 +89,25 @@ int sc_asn1_read_tag(const u8 ** buf, size_t buflen, unsigned int *cla_out,
|
|||
|
||||
scconf_block *_get_conf_block(sc_context_t *ctx, const char *name1, const char *name2, int priority);
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/* pkcs1 padding/encoding functions */
|
||||
/********************************************************************/
|
||||
|
||||
int sc_pkcs1_add_01_padding(const u8 *in, size_t in_len, u8 *out,
|
||||
size_t *out_len, size_t mod_length);
|
||||
int sc_pkcs1_strip_01_padding(const u8 *in_dat, size_t in_len, u8 *out_dat,
|
||||
size_t *out_len);
|
||||
int sc_pkcs1_strip_02_padding(const u8 *data, size_t len, u8 *out_dat,
|
||||
size_t *out_len);
|
||||
int sc_pkcs1_add_digest_info_prefix(unsigned int algorithm, const u8 *in_dat,
|
||||
size_t in_len, u8 *out_dat, size_t *out_len);
|
||||
int sc_pkcs1_strip_digest_info_prefix(unsigned int *algorithm,
|
||||
const u8 *in_dat, size_t in_len, u8 *out_dat, size_t *out_len);
|
||||
int sc_pkcs1_encode(sc_context_t *ctx, unsigned long flags,
|
||||
const u8 *in, size_t in_len, u8 *out, size_t *out_len, size_t mod_len);
|
||||
int sc_strip_zero_padding(const u8 *in,size_t in_len, u8 *out, size_t *out_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* opensc.h: OpenSC library header file
|
||||
*
|
||||
* Copyright (C) 2001, 2002 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* 2005 The OpenSC project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -775,7 +776,10 @@ int sc_lock(sc_card_t *card);
|
|||
*/
|
||||
int sc_unlock(sc_card_t *card);
|
||||
|
||||
/* ISO 7816-4 related functions */
|
||||
|
||||
/********************************************************************/
|
||||
/* ISO 7816-4 related functions */
|
||||
/********************************************************************/
|
||||
|
||||
/**
|
||||
* Does the equivalent of ISO 7816-4 command SELECT FILE.
|
||||
|
@ -821,7 +825,10 @@ int sc_put_data(sc_card_t *, unsigned int, const u8 *, size_t);
|
|||
|
||||
int sc_get_challenge(sc_card_t *card, u8 * rndout, size_t len);
|
||||
|
||||
/* ISO 7816-8 related functions */
|
||||
/********************************************************************/
|
||||
/* ISO 7816-8 related functions */
|
||||
/********************************************************************/
|
||||
|
||||
int sc_restore_security_env(sc_card_t *card, int se_num);
|
||||
int sc_set_security_env(sc_card_t *card,
|
||||
const struct sc_security_env *env, int se_num);
|
||||
|
@ -841,21 +848,12 @@ int sc_reset_retry_counter(sc_card_t *card, unsigned int type,
|
|||
int ref, const u8 *puk, size_t puklen,
|
||||
const u8 *newref, size_t newlen);
|
||||
int sc_build_pin(u8 *buf, size_t buflen, struct sc_pin_cmd_pin *pin, int pad);
|
||||
/* pkcs1 padding/encoding functions */
|
||||
int sc_pkcs1_add_01_padding(const u8 *in, size_t in_len, u8 *out,
|
||||
size_t *out_len, size_t mod_length);
|
||||
int sc_pkcs1_strip_01_padding(const u8 *in_dat, size_t in_len, u8 *out_dat,
|
||||
size_t *out_len);
|
||||
int sc_pkcs1_strip_02_padding(const u8 *data, size_t len, u8 *out_dat,
|
||||
size_t *out_len);
|
||||
int sc_pkcs1_add_digest_info_prefix(unsigned int algorithm, const u8 *in_dat,
|
||||
size_t in_len, u8 *out_dat, size_t *out_len);
|
||||
int sc_pkcs1_strip_digest_info_prefix(unsigned int *algorithm,
|
||||
const u8 *in_dat, size_t in_len, u8 *out_dat, size_t *out_len);
|
||||
int sc_pkcs1_encode(sc_context_t *ctx, unsigned long flags,
|
||||
const u8 *in, size_t in_len, u8 *out, size_t *out_len, size_t mod_len);
|
||||
int sc_strip_zero_padding(const u8 *in,size_t in_len, u8 *out, size_t *out_len);
|
||||
/* ISO 7816-9 */
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/* ISO 7816-9 related functions */
|
||||
/********************************************************************/
|
||||
|
||||
int sc_create_file(sc_card_t *card, sc_file_t *file);
|
||||
int sc_delete_file(sc_card_t *card, const sc_path_t *path);
|
||||
|
||||
|
@ -886,8 +884,27 @@ int sc_compare_path(const sc_path_t *, const sc_path_t *);
|
|||
int sc_append_path(sc_path_t *dest, const sc_path_t *src);
|
||||
int sc_append_path_id(sc_path_t *dest, const u8 *id, size_t idlen);
|
||||
int sc_append_file_id(sc_path_t *dest, unsigned int fid);
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/* miscellaneous functions */
|
||||
/********************************************************************/
|
||||
|
||||
int sc_hex_to_bin(const char *in, u8 *out, size_t *outlen);
|
||||
int sc_bin_to_hex(const u8 *, size_t, char *, size_t, int separator);
|
||||
/**
|
||||
* Converts a given OID in ascii form to a internal sc_object_id object
|
||||
* @param oid OUT sc_object_id object for the result
|
||||
* @param in ascii string with the oid ("1.2.3.4.5...")
|
||||
* @return SC_SUCCESS or an error value if an error occurred.
|
||||
*/
|
||||
int sc_format_oid(struct sc_object_id *oid, const char *in);
|
||||
/**
|
||||
* Compares two sc_object_id objects
|
||||
* @param oid1 the first sc_object_id object
|
||||
* @param oid2 the second sc_object_id object
|
||||
* @return 0 if the oids are equal and a non-zero value otherwise
|
||||
*/
|
||||
int sc_compare_oid(const struct sc_object_id *oid1, const struct sc_object_id *oid2);
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
@ -110,6 +111,33 @@ int sc_bin_to_hex(const u8 *in, size_t in_len, char *out, size_t out_len,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sc_format_oid(struct sc_object_id *oid, const char *in)
|
||||
{
|
||||
int ii, ret = SC_ERROR_INVALID_ARGUMENTS;
|
||||
const char *p;
|
||||
char *q;
|
||||
|
||||
if (oid == NULL || in == NULL)
|
||||
return ret;
|
||||
/* init oid */
|
||||
for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
|
||||
oid->value[ii] = -1;
|
||||
|
||||
p = in;
|
||||
|
||||
for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++) {
|
||||
oid->value[ii] = strtol(p, &q, 10);
|
||||
if (!*q)
|
||||
break;
|
||||
if (!(q[0] == '.' && isdigit(q[1]))) {
|
||||
return ret;
|
||||
}
|
||||
p = q + 1;
|
||||
}
|
||||
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
int sc_compare_oid(const struct sc_object_id *oid1, const struct sc_object_id *oid2)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -1808,7 +1808,7 @@ read_object(CK_SLOT_ID slot, CK_SESSION_HANDLE session)
|
|||
}
|
||||
|
||||
if (opt_application_id != NULL) {
|
||||
parse_application_id(&oid, opt_application_id);
|
||||
sc_format_oid(&oid, opt_application_id);
|
||||
FILL_ATTR(attrs[nn_attrs], CKA_OBJECT_ID,
|
||||
(unsigned char *)oid.value, sizeof(oid.value));
|
||||
nn_attrs++;
|
||||
|
|
|
@ -1036,7 +1036,7 @@ do_store_data_object(struct sc_profile *profile)
|
|||
args.label = opt_label;
|
||||
args.app_label = "pkcs15-init";
|
||||
|
||||
parse_application_id(&args.app_oid, opt_application_id);
|
||||
sc_format_oid(&args.app_oid, opt_application_id);
|
||||
|
||||
r = do_read_data_object(opt_infile, &data, &datalen);
|
||||
if (r >= 0) {
|
||||
|
@ -1192,7 +1192,7 @@ do_delete_objects(struct sc_profile *profile, unsigned int opt_delete_flags)
|
|||
sc_pkcs15_object_t *obj;
|
||||
if (opt_application_id == NULL)
|
||||
fatal("Specify the --application-id for the data object to be deleted\n");
|
||||
parse_application_id(&app_oid, opt_application_id);
|
||||
sc_format_oid(&app_oid, opt_application_id);
|
||||
|
||||
r = sc_pkcs15_find_data_object_by_app_oid(p15card, &app_oid, &obj);
|
||||
if (r >= 0) {
|
||||
|
|
|
@ -307,7 +307,7 @@ static int read_data_object(void)
|
|||
}
|
||||
count = r;
|
||||
|
||||
r = parse_application_id(&oid, opt_data);
|
||||
r = sc_format_oid(&oid, opt_data);
|
||||
if (r == SC_SUCCESS) {
|
||||
while (oid.value[oid_len] >= 0) oid_len++;
|
||||
}
|
||||
|
|
|
@ -271,32 +271,3 @@ warn(const char *fmt, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
int parse_application_id(struct sc_object_id *oid, char *oid_str)
|
||||
{
|
||||
int ii, ret = SC_ERROR_INVALID_ARGUMENTS;
|
||||
char *p, *q;
|
||||
|
||||
if (!oid)
|
||||
return ret;
|
||||
/* init oid */
|
||||
for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
|
||||
oid->value[ii] = -1;
|
||||
|
||||
if (!(p = oid_str))
|
||||
return ret;
|
||||
|
||||
for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++) {
|
||||
oid->value[ii] = strtol(p, &q, 10);
|
||||
if (!*q)
|
||||
break;
|
||||
if (!(q[0] == '.' && isdigit(q[1]))) {
|
||||
return ret;
|
||||
}
|
||||
p = q + 1;
|
||||
}
|
||||
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ void fatal(const char *fmt, ...);
|
|||
/* All singing all dancing card connect routine */
|
||||
int connect_card(struct sc_context *, struct sc_card **,
|
||||
int reader_id, int slot_id, int wait, int verbose);
|
||||
int parse_application_id(struct sc_object_id *oid, char *oid_str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue