12 #include "ct_keyinfo_p.h"
14 #include <gwenhywfar/misc.h>
15 #include <gwenhywfar/debug.h>
28 if (strcasecmp(p_s,
"free") == 0)
30 else if (strcasecmp(p_s,
"new") == 0)
32 else if (strcasecmp(p_s,
"active") == 0)
57 p_struct->_refCount = 1;
62 p_struct->keyDescr =
NULL;
64 p_struct->keySize = 0;
65 p_struct->cryptAlgoId = 0;
66 p_struct->modulus =
NULL;
67 p_struct->exponent =
NULL;
68 p_struct->keyNumber = 0;
69 p_struct->keyVersion = 0;
70 p_struct->signCounter = 0;
71 p_struct->certificate =
NULL;
80 assert(p_struct->_refCount);
81 if (p_struct->_refCount == 1) {
85 free(p_struct->keyDescr);
86 p_struct->keyDescr =
NULL;
88 p_struct->modulus =
NULL;
90 p_struct->exponent =
NULL;
92 p_struct->certificate =
NULL;
93 p_struct->_refCount = 0;
96 p_struct->_refCount--;
103 assert(p_struct->_refCount);
104 p_struct->_refCount++;
114 p_struct->id = p_src->id;
117 if (p_struct->keyDescr) {
118 free(p_struct->keyDescr);
119 p_struct->keyDescr =
NULL;
120 p_struct->keyDescr =
NULL;
122 if (p_src->keyDescr) {
123 p_struct->keyDescr = strdup(p_src->keyDescr);
127 p_struct->flags = p_src->flags;
130 p_struct->keySize = p_src->keySize;
133 p_struct->cryptAlgoId = p_src->cryptAlgoId;
136 if (p_struct->modulus) {
138 p_struct->modulus =
NULL;
139 p_struct->modulus =
NULL;
141 if (p_src->modulus) {
146 if (p_struct->exponent) {
148 p_struct->exponent =
NULL;
149 p_struct->exponent =
NULL;
151 if (p_src->exponent) {
156 p_struct->keyNumber = p_src->keyNumber;
159 p_struct->keyVersion = p_src->keyVersion;
162 p_struct->signCounter = p_src->signCounter;
165 if (p_struct->certificate) {
167 p_struct->certificate =
NULL;
168 p_struct->certificate =
NULL;
170 if (p_src->certificate) {
182 p_struct->id = p_src->id;
185 if (p_struct->keyDescr) {
186 free(p_struct->keyDescr);
187 p_struct->keyDescr =
NULL;
188 p_struct->keyDescr =
NULL;
190 if (p_src->keyDescr) {
191 p_struct->keyDescr = strdup(p_src->keyDescr);
195 p_struct->flags = p_src->flags;
198 p_struct->keySize = p_src->keySize;
201 p_struct->cryptAlgoId = p_src->cryptAlgoId;
204 if (p_struct->modulus) {
206 p_struct->modulus =
NULL;
207 p_struct->modulus =
NULL;
209 if (p_src->modulus) {
214 if (p_struct->exponent) {
216 p_struct->exponent =
NULL;
217 p_struct->exponent =
NULL;
219 if (p_src->exponent) {
224 p_struct->keyNumber = p_src->keyNumber;
227 p_struct->keyVersion = p_src->keyVersion;
230 p_struct->signCounter = p_src->signCounter;
233 if (p_struct->certificate) {
235 p_struct->certificate =
NULL;
236 p_struct->certificate =
NULL;
238 if (p_src->certificate) {
254 return p_struct->keyDescr;
260 return p_struct->flags;
266 return p_struct->keySize;
272 return p_struct->cryptAlgoId;
278 return p_struct->keyNumber;
284 return p_struct->keyVersion;
290 return p_struct->signCounter;
296 p_struct->id = p_src;
302 if (p_struct->keyDescr) {
303 free(p_struct->keyDescr);
304 p_struct->keyDescr =
NULL;
307 p_struct->keyDescr = strdup(p_src);
309 p_struct->keyDescr =
NULL;
316 p_struct->flags = p_src;
322 p_struct->flags |= p_src;
328 p_struct->flags &= ~p_src;
334 p_struct->keySize = p_src;
340 p_struct->cryptAlgoId = p_src;
346 p_struct->keyNumber = p_src;
352 p_struct->keyVersion = p_src;
358 p_struct->signCounter = p_src;
388 if (p_struct->keyDescr) {
389 free(p_struct->keyDescr);
390 p_struct->keyDescr =
NULL;
395 if (s) p_struct->keyDescr = strdup(s);
397 if (p_struct->keyDescr ==
NULL) {
398 p_struct->keyDescr =
NULL;
411 if (p_struct->modulus) {
413 p_struct->modulus =
NULL;
424 if (p_struct->modulus ==
NULL) {
425 p_struct->modulus =
NULL;
429 if (p_struct->exponent) {
431 p_struct->exponent =
NULL;
442 if (p_struct->exponent ==
NULL) {
443 p_struct->exponent =
NULL;
456 if (p_struct->certificate) {
458 p_struct->certificate =
NULL;
469 if (p_struct->certificate ==
NULL) {
470 p_struct->certificate =
NULL;
596 if (p_struct->keyDescr) {
597 free(p_struct->keyDescr);
598 p_struct->keyDescr =
NULL;
603 if (s) p_struct->keyDescr = strdup(s);
605 if (p_struct->keyDescr ==
NULL) {
606 p_struct->keyDescr =
NULL;
619 if (p_struct->modulus) {
621 p_struct->modulus =
NULL;
631 if (p_struct->modulus ==
NULL) {
632 p_struct->modulus =
NULL;
636 if (p_struct->exponent) {
638 p_struct->exponent =
NULL;
648 if (p_struct->exponent ==
NULL) {
649 p_struct->exponent =
NULL;
662 if (p_struct->certificate) {
664 p_struct->certificate =
NULL;
674 if (p_struct->certificate ==
NULL) {
675 p_struct->certificate =
NULL;
699 if (p_struct->modulus) {
708 if (p_struct->exponent) {
726 if (p_struct->certificate) {
758 if (p_struct->id == p_cmp) p_rv = 0;
759 else if (p_cmp < p_struct->
id) p_rv = -1;
774 ki->keySize = keySize;
784 }
else st->modulus =
NULL;
805 }
else st->exponent =
NULL;
826 }
else st->certificate =
NULL;
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
#define GWEN_DB_FLAGS_OVERWRITE_VARS
struct GWEN_DB_NODE GWEN_DB_NODE
#define GWEN_INHERIT_FINI(t, element)
const uint8_t * GWEN_Crypt_Token_KeyInfo_GetModulusData(const GWEN_CRYPT_TOKEN_KEYINFO *st)
void GWEN_Crypt_Token_KeyInfo_SetCertificate(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
uint32_t GWEN_Crypt_Token_KeyInfo_GetId(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
void GWEN_Crypt_Token_KeyInfo_free(GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
void GWEN_Crypt_Token_KeyInfo_Attach(GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo__new(void)
#define GWEN_FREE_OBJECT(varname)
void GWEN_Crypt_Token_KeyInfo_SetModulus(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
GWEN_CRYPT_TOKEN_KEYINFO_LIST * GWEN_Crypt_Token_KeyInfo_List_dup(const GWEN_CRYPT_TOKEN_KEYINFO_LIST *p_src)
void GWEN_XMLNode_SetCharValue(GWEN_XMLNODE *n, const char *name, const char *value)
uint32_t GWEN_Crypt_Token_KeyInfo_GetCertificateLen(const GWEN_CRYPT_TOKEN_KEYINFO *st)
void GWEN_Crypt_Token_KeyInfo_toXml(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_XMLNODE *p_db)
uint32_t GWEN_Crypt_Token_KeyInfo_GetSignCounter(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_List_GetById(const GWEN_CRYPT_TOKEN_KEYINFO_LIST *p_list, uint32_t p_cmp)
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
int GWEN_XMLNode_GetIntValue(const GWEN_XMLNODE *n, const char *name, int defValue)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_dup(const GWEN_CRYPT_TOKEN_KEYINFO *p_src)
uint32_t GWEN_Crypt_Token_KeyInfo_GetModulusLen(const GWEN_CRYPT_TOKEN_KEYINFO *st)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_copy(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, const GWEN_CRYPT_TOKEN_KEYINFO *p_src)
GWEN_CRYPT_TOKEN_KEYINFO_LIST * GWEN_Crypt_Token_KeyInfo_List_new()
int GWEN_DB_SetBinValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const void *val, unsigned int valSize)
#define GWEN_NEW_OBJECT(typ, varname)
GWEN_CRYPT_TOKEN_KEYSTATUS
uint32_t GWEN_Crypt_Token_KeyInfo_GetKeyVersion(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_fromDb(GWEN_DB_NODE *p_db)
const char * GWEN_XMLNode_GetCharValue(const GWEN_XMLNODE *n, const char *name, const char *defValue)
int GWEN_Crypt_Token_KeyInfo_GetKeySize(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
const uint8_t * GWEN_Crypt_Token_KeyInfo_GetExponentData(const GWEN_CRYPT_TOKEN_KEYINFO *st)
void GWEN_Crypt_Token_KeyInfo_SetKeyVersion(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
const void * GWEN_DB_GetBinValue(GWEN_DB_NODE *n, const char *path, int idx, const void *defVal, unsigned int defValSize, unsigned int *returnValueSize)
const char * GWEN_Crypt_Token_KeyStatus_toString(GWEN_CRYPT_TOKEN_KEYSTATUS p_i)
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
uint32_t GWEN_Crypt_Token_KeyInfo_GetFlags(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
#define GWEN_INHERIT_INIT(t, element)
int GWEN_Crypt_Token_KeyInfo_GetCryptAlgoId(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_List_First(const GWEN_CRYPT_TOKEN_KEYINFO_LIST *l)
void GWEN_Crypt_Token_KeyInfo_SetCryptAlgoId(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, int p_src)
GWEN_BUFFER * GWEN_Buffer_dup(GWEN_BUFFER *bf)
void GWEN_Buffer_free(GWEN_BUFFER *bf)
int GWEN_DB_DeleteVar(GWEN_DB_NODE *n, const char *path)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
GWEN_LIST2_FUNCTIONS(TYPEMAKER2_TYPE, Typemaker2_Type)
GWEN_CRYPT_TOKEN_KEYSTATUS GWEN_Crypt_Token_KeyStatus_fromString(const char *p_s)
const char * GWEN_Crypt_Token_KeyInfo_GetKeyDescr(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
struct GWEN_CRYPT_TOKEN_KEYINFO GWEN_CRYPT_TOKEN_KEYINFO
int GWEN_Crypt_Token_KeyInfo_toDb(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_DB_NODE *p_db)
void GWEN_Crypt_Token_KeyInfo_List_Add(GWEN_CRYPT_TOKEN_KEYINFO *element, GWEN_CRYPT_TOKEN_KEYINFO_LIST *list)
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
void GWEN_Crypt_Token_KeyInfo_SetExponent(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
#define DBG_INFO(dbg_logger, format, args...)
void GWEN_Crypt_Token_KeyInfo_WriteXml(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_XMLNODE *p_db)
void GWEN_Crypt_Token_KeyInfo_SetFlags(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
uint32_t GWEN_Crypt_Token_KeyInfo_GetExponentLen(const GWEN_CRYPT_TOKEN_KEYINFO *st)
void GWEN_Crypt_Token_KeyInfo_SetKeyNumber(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
#define GWEN_LIST_INIT(t, element)
void GWEN_Crypt_Token_KeyInfo_ReadDb(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_DB_NODE *p_db)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_new(uint32_t kid, GWEN_CRYPT_CRYPTALGOID a, int keySize)
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
void GWEN_Crypt_Token_KeyInfo_SetSignCounter(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
void GWEN_Crypt_Token_KeyInfo_SubFlags(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
int GWEN_Buffer_AppendBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
void GWEN_Crypt_Token_KeyInfo_ReadXml(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_XMLNODE *p_db)
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
#define GWEN_LIST_FUNCTIONS(t, pr)
void GWEN_Crypt_Token_KeyInfo_SetKeySize(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, int p_src)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_fromXml(GWEN_XMLNODE *p_db)
void GWEN_Crypt_Token_KeyInfo_SetId(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_List_Next(const GWEN_CRYPT_TOKEN_KEYINFO *element)
int GWEN_Text_FromHexBuffer(const char *src, GWEN_BUFFER *buf)
void GWEN_Crypt_Token_KeyInfo_SetKeyDescr(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, const char *p_src)
#define GWEN_LIST_FINI(t, element)
#define GWEN_INHERIT_FUNCTIONS(t)
int GWEN_Text_ToHexBuffer(const char *src, unsigned l, GWEN_BUFFER *buf, unsigned int groupsize, char delimiter, int skipLeadingZeroes)
struct GWEN__XMLNODE GWEN_XMLNODE
uint32_t GWEN_Crypt_Token_KeyInfo_GetKeyNumber(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
void GWEN_Crypt_Token_KeyInfo_AddFlags(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
void GWEN_XMLNode_SetIntValue(GWEN_XMLNODE *n, const char *name, int value)
int GWEN_Crypt_Token_KeyInfo_WriteDb(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_DB_NODE *p_db)
const uint8_t * GWEN_Crypt_Token_KeyInfo_GetCertificateData(const GWEN_CRYPT_TOKEN_KEYINFO *st)