mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 18:57:27 +02:00
add obj_name_do_all
This commit is contained in:
61
tests/api.c
61
tests/api.c
@ -46124,7 +46124,7 @@ static void list_md_fn(const EVP_MD* m, const char* from,
|
|||||||
|
|
||||||
bio = BIO_new(BIO_s_file());
|
bio = BIO_new(BIO_s_file());
|
||||||
BIO_set_fp(bio, arg, BIO_NOCLOSE);
|
BIO_set_fp(bio, arg, BIO_NOCLOSE);
|
||||||
BIO_printf(bio, "-%-14s to use the %s message digest algorithm\n", mn, mn);
|
BIO_printf(bio, "Use %s message digest algorithm\n", mn);
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -46135,6 +46135,11 @@ static void test_EVP_MD_do_all()
|
|||||||
#if defined(OPENSSL_EXTRA)
|
#if defined(OPENSSL_EXTRA)
|
||||||
printf(testingFmt, "test_EVP_MD_do_all");
|
printf(testingFmt, "test_EVP_MD_do_all");
|
||||||
|
|
||||||
|
EVP_MD_do_all(NULL, stdout);
|
||||||
|
/* to confirm previous call gives no harm */
|
||||||
|
AssertTrue(1);
|
||||||
|
|
||||||
|
|
||||||
EVP_MD_do_all(list_md_fn, stdout);
|
EVP_MD_do_all(list_md_fn, stdout);
|
||||||
/* to confirm previous call gives no harm */
|
/* to confirm previous call gives no harm */
|
||||||
AssertTrue(1);
|
AssertTrue(1);
|
||||||
@ -46142,6 +46147,59 @@ static void test_EVP_MD_do_all()
|
|||||||
printf(resultFmt, passed);
|
printf(resultFmt, passed);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(OPENSSL_EXTRA)
|
||||||
|
static void obj_name_t(const OBJ_NAME* nm, void* arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
(void)nm;
|
||||||
|
|
||||||
|
AssertIntGT(nm->type, OBJ_NAME_TYPE_UNDEF);
|
||||||
|
|
||||||
|
#if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
|
||||||
|
/* print to stdout */
|
||||||
|
AssertNotNull(arg);
|
||||||
|
|
||||||
|
bio = BIO_new(BIO_s_file());
|
||||||
|
BIO_set_fp(bio, arg, BIO_NOCLOSE);
|
||||||
|
BIO_printf(bio, "%s\n", mn);
|
||||||
|
BIO_free(bio);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
static void test_OBJ_NAME_do_all()
|
||||||
|
{
|
||||||
|
#if defined(OPENSSL_EXTRA)
|
||||||
|
printf(testingFmt, "test_OBJ_NAME_do_all");
|
||||||
|
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, NULL, NULL);
|
||||||
|
/* to confirm previous call gives no harm */
|
||||||
|
AssertTrue(1);
|
||||||
|
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, NULL, stdout);
|
||||||
|
/* to confirm previous call gives no harm */
|
||||||
|
AssertTrue(1);
|
||||||
|
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, obj_name_t, stdout);
|
||||||
|
AssertTrue(1);
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_PKEY_METH, obj_name_t, stdout);
|
||||||
|
AssertTrue(1);
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_COMP_METH, obj_name_t, stdout);
|
||||||
|
AssertTrue(1);
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_NUM, obj_name_t, stdout);
|
||||||
|
AssertTrue(1);
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_UNDEF, obj_name_t, stdout);
|
||||||
|
AssertTrue(1);
|
||||||
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, obj_name_t, stdout);
|
||||||
|
AssertTrue(1);
|
||||||
|
OBJ_NAME_do_all(-1, obj_name_t, stdout);
|
||||||
|
AssertTrue(1);
|
||||||
|
|
||||||
|
printf(resultFmt, passed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*
|
/*----------------------------------------------------------------------------*
|
||||||
| Main
|
| Main
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
@ -46165,6 +46223,7 @@ void ApiTest(void)
|
|||||||
test_wolfSSL_ERR_strings();
|
test_wolfSSL_ERR_strings();
|
||||||
test_EVP_blake2();
|
test_EVP_blake2();
|
||||||
test_EVP_MD_do_all();
|
test_EVP_MD_do_all();
|
||||||
|
test_OBJ_NAME_do_all();
|
||||||
test_wolfSSL_CTX_use_certificate_file();
|
test_wolfSSL_CTX_use_certificate_file();
|
||||||
AssertIntEQ(test_wolfSSL_CTX_use_certificate_buffer(), WOLFSSL_SUCCESS);
|
AssertIntEQ(test_wolfSSL_CTX_use_certificate_buffer(), WOLFSSL_SUCCESS);
|
||||||
test_wolfSSL_CTX_use_PrivateKey_file();
|
test_wolfSSL_CTX_use_PrivateKey_file();
|
||||||
|
@ -3956,7 +3956,43 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
|||||||
return aliasnm;
|
return aliasnm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do all md algorithm through a callback function
|
|
||||||
|
struct do_all_md {
|
||||||
|
void *arg;
|
||||||
|
void (*fn) (const WOLFSSL_EVP_MD *m,
|
||||||
|
const char* from, const char* to, void *arg);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* do all md algorithm
|
||||||
|
* @param nm a pointer to WOLFSSL_OBJ_NAME
|
||||||
|
* @param arg arguments to pass to the callback
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
static void md_do_all_func(const WOLFSSL_OBJ_NAME* nm, void* arg)
|
||||||
|
{
|
||||||
|
struct do_all_md *md = arg;
|
||||||
|
|
||||||
|
const char* alias = NULL;
|
||||||
|
const struct s_ent *ent;
|
||||||
|
|
||||||
|
/* sanity check */
|
||||||
|
if (md == NULL || nm == NULL || md->fn == NULL ||
|
||||||
|
nm->type != WOLFSSL_OBJ_NAME_TYPE_MD_METH)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* loop all md */
|
||||||
|
for (ent = md_tbl; ent->name != NULL; ent++){
|
||||||
|
/* check if the md has alias */
|
||||||
|
if((alias = hasAliasName(ent->name)) != NULL) {
|
||||||
|
md->fn(NULL, ent->name, ent->name, md->arg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
md->fn(ent->name, ent->name, NULL, md->arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* call md_do_all function to do all md algorithm via a callback function
|
||||||
* @param fn a callback function to be called with all 'md'
|
* @param fn a callback function to be called with all 'md'
|
||||||
* @param args arguments to pass to the callback
|
* @param args arguments to pass to the callback
|
||||||
* @return none
|
* @return none
|
||||||
@ -3964,18 +4000,45 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
|||||||
void wolfSSL_EVP_MD_do_all(void (*fn) (const WOLFSSL_EVP_MD *m,
|
void wolfSSL_EVP_MD_do_all(void (*fn) (const WOLFSSL_EVP_MD *m,
|
||||||
const char* from, const char* to, void* xx), void* args)
|
const char* from, const char* to, void* xx), void* args)
|
||||||
{
|
{
|
||||||
const char* alias = NULL;
|
struct do_all_md md;
|
||||||
const struct s_ent *ent;
|
|
||||||
|
|
||||||
/* loop all md */
|
md.fn = fn;
|
||||||
for (ent = md_tbl; ent->name != NULL; ent++){
|
md.arg = args;
|
||||||
/* check if the md has alias */
|
|
||||||
if((alias = hasAliasName(ent->name)) != NULL) {
|
return wolfSSL_OBJ_NAME_do_all(WOLFSSL_OBJ_NAME_TYPE_MD_METH,
|
||||||
fn(NULL, ent->name, ent->name, args);
|
md_do_all_func, &md);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
fn(ent->name, ent->name, NULL, args);
|
/* call "fn" based on OBJ_NAME type
|
||||||
}
|
* @param type OBJ_NAME type
|
||||||
|
* @param fn a callback function
|
||||||
|
* @param args arguments to pass to the callback
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
void wolfSSL_OBJ_NAME_do_all(int type,
|
||||||
|
void (*fn)(const WOLFSSL_OBJ_NAME*, void* arg), void* arg)
|
||||||
|
{
|
||||||
|
WOLFSSL_OBJ_NAME objnm;
|
||||||
|
|
||||||
|
/* sanity check */
|
||||||
|
if (!fn)
|
||||||
|
return;
|
||||||
|
|
||||||
|
objnm.type = type;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case WOLFSSL_OBJ_NAME_TYPE_MD_METH:
|
||||||
|
fn(&objnm, arg);
|
||||||
|
break;
|
||||||
|
case WOLFSSL_OBJ_NAME_TYPE_CIPHER_METH:
|
||||||
|
case WOLFSSL_OBJ_NAME_TYPE_PKEY_METH:
|
||||||
|
case WOLFSSL_OBJ_NAME_TYPE_COMP_METH:
|
||||||
|
case WOLFSSL_OBJ_NAME_TYPE_NUM:
|
||||||
|
WOLFSSL_MSG("not implemented");
|
||||||
|
FALL_THROUGH;
|
||||||
|
case WOLFSSL_OBJ_NAME_TYPE_UNDEF:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,14 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define OBJ_NAME_TYPE_UNDEF WOLFSSL_OBJ_NAME_TYPE_UNDEF
|
||||||
|
#define OBJ_NAME_TYPE_MD_METH WOLFSSL_OBJ_NAME_TYPE_MD_METH
|
||||||
|
#define OBJ_NAME_TYPE_CIPHER_METH WOLFSSL_OBJ_NAME_TYPE_CIPHER_METH
|
||||||
|
#define OBJ_NAME_TYPE_PKEY_METH WOLFSSL_OBJ_NAME_TYPE_PKEY_METH
|
||||||
|
#define OBJ_NAME_TYPE_COMP_METH WOLFSSL_OBJ_NAME_TYPE_COMP_METH
|
||||||
|
#define OBJ_NAME_TYPE_NUM WOLFSSL_OBJ_NAME_TYPE_NUM
|
||||||
|
#define OBJ_NAME_ALIAS WOLFSSL_OBJ_NAME_ALIAS
|
||||||
|
|
||||||
#define OBJ_nid2sn wolfSSL_OBJ_nid2sn
|
#define OBJ_nid2sn wolfSSL_OBJ_nid2sn
|
||||||
#define OBJ_obj2nid wolfSSL_OBJ_obj2nid
|
#define OBJ_obj2nid wolfSSL_OBJ_obj2nid
|
||||||
#define OBJ_sn2nid wolfSSL_OBJ_sn2nid
|
#define OBJ_sn2nid wolfSSL_OBJ_sn2nid
|
||||||
@ -47,6 +55,7 @@
|
|||||||
#define OBJ_cmp wolfSSL_OBJ_cmp
|
#define OBJ_cmp wolfSSL_OBJ_cmp
|
||||||
#define OBJ_create wolfSSL_OBJ_create
|
#define OBJ_create wolfSSL_OBJ_create
|
||||||
#define ASN1_OBJECT_free wolfSSL_ASN1_OBJECT_free
|
#define ASN1_OBJECT_free wolfSSL_ASN1_OBJECT_free
|
||||||
|
#define OBJ_NAME_do_all wolfSSL_OBJ_NAME_do_all
|
||||||
|
|
||||||
/* not required for wolfSSL */
|
/* not required for wolfSSL */
|
||||||
#define OPENSSL_load_builtin_modules()
|
#define OPENSSL_load_builtin_modules()
|
||||||
|
@ -111,6 +111,7 @@ typedef WOLFSSL_dynlock_value CRYPTO_dynlock_value;
|
|||||||
typedef WOLFSSL_BUF_MEM BUF_MEM;
|
typedef WOLFSSL_BUF_MEM BUF_MEM;
|
||||||
typedef WOLFSSL_GENERAL_NAMES GENERAL_NAMES;
|
typedef WOLFSSL_GENERAL_NAMES GENERAL_NAMES;
|
||||||
typedef WOLFSSL_GENERAL_NAME GENERAL_NAME;
|
typedef WOLFSSL_GENERAL_NAME GENERAL_NAME;
|
||||||
|
typedef WOLFSSL_OBJ_NAME OBJ_NAME;
|
||||||
|
|
||||||
#define X509_L_FILE_LOAD WOLFSSL_X509_L_FILE_LOAD
|
#define X509_L_FILE_LOAD WOLFSSL_X509_L_FILE_LOAD
|
||||||
#define X509_L_ADD_DIR WOLFSSL_X509_L_ADD_DIR
|
#define X509_L_ADD_DIR WOLFSSL_X509_L_ADD_DIR
|
||||||
|
@ -197,6 +197,7 @@ typedef struct WOLFSSL_ASN1_OBJECT WOLFSSL_ASN1_OBJECT;
|
|||||||
typedef struct WOLFSSL_ASN1_OTHERNAME WOLFSSL_ASN1_OTHERNAME;
|
typedef struct WOLFSSL_ASN1_OTHERNAME WOLFSSL_ASN1_OTHERNAME;
|
||||||
typedef struct WOLFSSL_X509V3_CTX WOLFSSL_X509V3_CTX;
|
typedef struct WOLFSSL_X509V3_CTX WOLFSSL_X509V3_CTX;
|
||||||
typedef struct WOLFSSL_v3_ext_method WOLFSSL_v3_ext_method;
|
typedef struct WOLFSSL_v3_ext_method WOLFSSL_v3_ext_method;
|
||||||
|
typedef struct WOLFSSL_OBJ_NAME WOLFSSL_OBJ_NAME;
|
||||||
|
|
||||||
typedef struct WOLFSSL_ASN1_STRING WOLFSSL_ASN1_STRING;
|
typedef struct WOLFSSL_ASN1_STRING WOLFSSL_ASN1_STRING;
|
||||||
typedef struct WOLFSSL_dynlock_value WOLFSSL_dynlock_value;
|
typedef struct WOLFSSL_dynlock_value WOLFSSL_dynlock_value;
|
||||||
@ -217,6 +218,10 @@ typedef struct WOLFSSL_CONF_CTX WOLFSSL_CONF_CTX;
|
|||||||
|
|
||||||
#if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
|
#if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
|
||||||
|
|
||||||
|
struct WOLFSSL_OBJ_NAME {
|
||||||
|
int type;
|
||||||
|
};
|
||||||
|
|
||||||
struct WOLFSSL_AUTHORITY_KEYID {
|
struct WOLFSSL_AUTHORITY_KEYID {
|
||||||
WOLFSSL_ASN1_STRING *keyid;
|
WOLFSSL_ASN1_STRING *keyid;
|
||||||
WOLFSSL_ASN1_OBJECT *issuer;
|
WOLFSSL_ASN1_OBJECT *issuer;
|
||||||
@ -3679,6 +3684,18 @@ WOLFSSL_API int wolfSSL_OBJ_create(const char *oid, const char *sn, const char *
|
|||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
WOLFSSL_LOCAL int NIDToEccEnum(int n);
|
WOLFSSL_LOCAL int NIDToEccEnum(int n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define WOLFSSL_OBJ_NAME_TYPE_UNDEF 0x00
|
||||||
|
#define WOLFSSL_OBJ_NAME_TYPE_MD_METH 0x01
|
||||||
|
#define WOLFSSL_OBJ_NAME_TYPE_CIPHER_METH 0x02
|
||||||
|
#define WOLFSSL_OBJ_NAME_TYPE_PKEY_METH 0x03
|
||||||
|
#define WOLFSSL_OBJ_NAME_TYPE_COMP_METH 0x04
|
||||||
|
#define WOLFSSL_OBJ_NAME_TYPE_NUM 0x05
|
||||||
|
#define WOLFSSL_OBJ_NAME_ALIAS 0x8000
|
||||||
|
|
||||||
|
WOLFSSL_API void wolfSSL_OBJ_NAME_do_all(int type,
|
||||||
|
void (*fn) (const WOLFSSL_OBJ_NAME* , void *arg),
|
||||||
|
void* arg);
|
||||||
/* end of object functions */
|
/* end of object functions */
|
||||||
|
|
||||||
WOLFSSL_API unsigned long wolfSSL_ERR_peek_last_error_line(const char **file, int *line);
|
WOLFSSL_API unsigned long wolfSSL_ERR_peek_last_error_line(const char **file, int *line);
|
||||||
|
Reference in New Issue
Block a user