jpayne@69: /* jpayne@69: * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. jpayne@69: * jpayne@69: * Licensed under the OpenSSL license (the "License"). You may not use jpayne@69: * this file except in compliance with the License. You can obtain a copy jpayne@69: * in the file LICENSE in the source distribution or at jpayne@69: * https://www.openssl.org/source/license.html jpayne@69: */ jpayne@69: jpayne@69: #ifndef HEADER_OBJECTS_H jpayne@69: # define HEADER_OBJECTS_H jpayne@69: jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: jpayne@69: # define OBJ_NAME_TYPE_UNDEF 0x00 jpayne@69: # define OBJ_NAME_TYPE_MD_METH 0x01 jpayne@69: # define OBJ_NAME_TYPE_CIPHER_METH 0x02 jpayne@69: # define OBJ_NAME_TYPE_PKEY_METH 0x03 jpayne@69: # define OBJ_NAME_TYPE_COMP_METH 0x04 jpayne@69: # define OBJ_NAME_TYPE_NUM 0x05 jpayne@69: jpayne@69: # define OBJ_NAME_ALIAS 0x8000 jpayne@69: jpayne@69: # define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01 jpayne@69: # define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02 jpayne@69: jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: typedef struct obj_name_st { jpayne@69: int type; jpayne@69: int alias; jpayne@69: const char *name; jpayne@69: const char *data; jpayne@69: } OBJ_NAME; jpayne@69: jpayne@69: # define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) jpayne@69: jpayne@69: int OBJ_NAME_init(void); jpayne@69: int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), jpayne@69: int (*cmp_func) (const char *, const char *), jpayne@69: void (*free_func) (const char *, int, const char *)); jpayne@69: const char *OBJ_NAME_get(const char *name, int type); jpayne@69: int OBJ_NAME_add(const char *name, int type, const char *data); jpayne@69: int OBJ_NAME_remove(const char *name, int type); jpayne@69: void OBJ_NAME_cleanup(int type); /* -1 for everything */ jpayne@69: void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg), jpayne@69: void *arg); jpayne@69: void OBJ_NAME_do_all_sorted(int type, jpayne@69: void (*fn) (const OBJ_NAME *, void *arg), jpayne@69: void *arg); jpayne@69: jpayne@69: ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o); jpayne@69: ASN1_OBJECT *OBJ_nid2obj(int n); jpayne@69: const char *OBJ_nid2ln(int n); jpayne@69: const char *OBJ_nid2sn(int n); jpayne@69: int OBJ_obj2nid(const ASN1_OBJECT *o); jpayne@69: ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name); jpayne@69: int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); jpayne@69: int OBJ_txt2nid(const char *s); jpayne@69: int OBJ_ln2nid(const char *s); jpayne@69: int OBJ_sn2nid(const char *s); jpayne@69: int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b); jpayne@69: const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, jpayne@69: int (*cmp) (const void *, const void *)); jpayne@69: const void *OBJ_bsearch_ex_(const void *key, const void *base, int num, jpayne@69: int size, jpayne@69: int (*cmp) (const void *, const void *), jpayne@69: int flags); jpayne@69: jpayne@69: # define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \ jpayne@69: static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \ jpayne@69: static int nm##_cmp(type1 const *, type2 const *); \ jpayne@69: scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) jpayne@69: jpayne@69: # define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \ jpayne@69: _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp) jpayne@69: # define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ jpayne@69: type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) jpayne@69: jpayne@69: /*- jpayne@69: * Unsolved problem: if a type is actually a pointer type, like jpayne@69: * nid_triple is, then its impossible to get a const where you need jpayne@69: * it. Consider: jpayne@69: * jpayne@69: * typedef int nid_triple[3]; jpayne@69: * const void *a_; jpayne@69: * const nid_triple const *a = a_; jpayne@69: * jpayne@69: * The assignment discards a const because what you really want is: jpayne@69: * jpayne@69: * const int const * const *a = a_; jpayne@69: * jpayne@69: * But if you do that, you lose the fact that a is an array of 3 ints, jpayne@69: * which breaks comparison functions. jpayne@69: * jpayne@69: * Thus we end up having to cast, sadly, or unpack the jpayne@69: * declarations. Or, as I finally did in this case, declare nid_triple jpayne@69: * to be a struct, which it should have been in the first place. jpayne@69: * jpayne@69: * Ben, August 2008. jpayne@69: * jpayne@69: * Also, strictly speaking not all types need be const, but handling jpayne@69: * the non-constness means a lot of complication, and in practice jpayne@69: * comparison routines do always not touch their arguments. jpayne@69: */ jpayne@69: jpayne@69: # define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \ jpayne@69: static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ jpayne@69: { \ jpayne@69: type1 const *a = a_; \ jpayne@69: type2 const *b = b_; \ jpayne@69: return nm##_cmp(a,b); \ jpayne@69: } \ jpayne@69: static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ jpayne@69: { \ jpayne@69: return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ jpayne@69: nm##_cmp_BSEARCH_CMP_FN); \ jpayne@69: } \ jpayne@69: extern void dummy_prototype(void) jpayne@69: jpayne@69: # define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ jpayne@69: static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ jpayne@69: { \ jpayne@69: type1 const *a = a_; \ jpayne@69: type2 const *b = b_; \ jpayne@69: return nm##_cmp(a,b); \ jpayne@69: } \ jpayne@69: type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ jpayne@69: { \ jpayne@69: return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ jpayne@69: nm##_cmp_BSEARCH_CMP_FN); \ jpayne@69: } \ jpayne@69: extern void dummy_prototype(void) jpayne@69: jpayne@69: # define OBJ_bsearch(type1,key,type2,base,num,cmp) \ jpayne@69: ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ jpayne@69: num,sizeof(type2), \ jpayne@69: ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ jpayne@69: (void)CHECKED_PTR_OF(type2,cmp##_type_2), \ jpayne@69: cmp##_BSEARCH_CMP_FN))) jpayne@69: jpayne@69: # define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags) \ jpayne@69: ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ jpayne@69: num,sizeof(type2), \ jpayne@69: ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ jpayne@69: (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \ jpayne@69: cmp##_BSEARCH_CMP_FN)),flags) jpayne@69: jpayne@69: int OBJ_new_nid(int num); jpayne@69: int OBJ_add_object(const ASN1_OBJECT *obj); jpayne@69: int OBJ_create(const char *oid, const char *sn, const char *ln); jpayne@69: #if OPENSSL_API_COMPAT < 0x10100000L jpayne@69: # define OBJ_cleanup() while(0) continue jpayne@69: #endif jpayne@69: int OBJ_create_objects(BIO *in); jpayne@69: jpayne@69: size_t OBJ_length(const ASN1_OBJECT *obj); jpayne@69: const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj); jpayne@69: jpayne@69: int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); jpayne@69: int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); jpayne@69: int OBJ_add_sigid(int signid, int dig_id, int pkey_id); jpayne@69: void OBJ_sigid_free(void); jpayne@69: jpayne@69: jpayne@69: # ifdef __cplusplus jpayne@69: } jpayne@69: # endif jpayne@69: #endif