gwenhywfar  5.10.1
ct_keyinfo.c
Go to the documentation of this file.
1 /**********************************************************
2  * This file has been automatically created by "typemaker2"
3  * from the file "ct_keyinfo.xml".
4  * Please do not edit this file, all changes will be lost.
5  * Better edit the mentioned source file instead.
6  **********************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11 
12 #include "ct_keyinfo_p.h"
13 
14 #include <gwenhywfar/misc.h>
15 #include <gwenhywfar/debug.h>
16 
17 /* code headers */
18 
19 /* macro functions */
20 GWEN_LIST_FUNCTIONS(GWEN_CRYPT_TOKEN_KEYINFO, GWEN_Crypt_Token_KeyInfo)
21 GWEN_LIST2_FUNCTIONS(GWEN_CRYPT_TOKEN_KEYINFO, GWEN_Crypt_Token_KeyInfo)
23 
24 
26 {
27  if (p_s && *p_s) {
28  if (strcasecmp(p_s, "free")==0)
30  else if (strcasecmp(p_s, "new")==0)
32  else if (strcasecmp(p_s, "active")==0)
34  }
36 }
37 
39 {
40  switch (p_i) {
42  return "free";
44  return "new";
46  return "active";
47  default:
48  return "unknown";
49  }
50 }
51 
53 {
54  GWEN_CRYPT_TOKEN_KEYINFO *p_struct;
55 
57  p_struct->_refCount=1;
60  /* members */
61  p_struct->id=0;
62  p_struct->keyDescr=NULL;
63  p_struct->flags=0;
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;
72  p_struct->certType=0;
73  /* virtual functions */
74 
75  return p_struct;
76 }
77 
79 {
80  if (p_struct) {
81  assert(p_struct->_refCount);
82  if (p_struct->_refCount==1) {
85  /* members */
86  free(p_struct->keyDescr);
87  p_struct->keyDescr=NULL;
88  GWEN_Buffer_free(p_struct->modulus);
89  p_struct->modulus=NULL;
90  GWEN_Buffer_free(p_struct->exponent);
91  p_struct->exponent=NULL;
92  GWEN_Buffer_free(p_struct->certificate);
93  p_struct->certificate=NULL;
94  p_struct->_refCount=0;
95  GWEN_FREE_OBJECT(p_struct);
96  }
97  else
98  p_struct->_refCount--;
99  }
100 }
101 
103 {
104  assert(p_struct);
105  assert(p_struct->_refCount);
106  p_struct->_refCount++;
107 }
108 
110 {
111  GWEN_CRYPT_TOKEN_KEYINFO *p_struct;
112 
113  assert(p_src);
115  /* member "id" */
116  p_struct->id=p_src->id;
117 
118  /* member "keyDescr" */
119  if (p_struct->keyDescr) {
120  free(p_struct->keyDescr);
121  p_struct->keyDescr=NULL;
122  p_struct->keyDescr=NULL;
123  }
124  if (p_src->keyDescr) {
125  p_struct->keyDescr=strdup(p_src->keyDescr);
126  }
127 
128  /* member "flags" */
129  p_struct->flags=p_src->flags;
130 
131  /* member "keySize" */
132  p_struct->keySize=p_src->keySize;
133 
134  /* member "cryptAlgoId" */
135  p_struct->cryptAlgoId=p_src->cryptAlgoId;
136 
137  /* member "modulus" */
138  if (p_struct->modulus) {
139  GWEN_Buffer_free(p_struct->modulus);
140  p_struct->modulus=NULL;
141  p_struct->modulus=NULL;
142  }
143  if (p_src->modulus) {
144  p_struct->modulus=GWEN_Buffer_dup(p_src->modulus);
145  }
146 
147  /* member "exponent" */
148  if (p_struct->exponent) {
149  GWEN_Buffer_free(p_struct->exponent);
150  p_struct->exponent=NULL;
151  p_struct->exponent=NULL;
152  }
153  if (p_src->exponent) {
154  p_struct->exponent=GWEN_Buffer_dup(p_src->exponent);
155  }
156 
157  /* member "keyNumber" */
158  p_struct->keyNumber=p_src->keyNumber;
159 
160  /* member "keyVersion" */
161  p_struct->keyVersion=p_src->keyVersion;
162 
163  /* member "signCounter" */
164  p_struct->signCounter=p_src->signCounter;
165 
166  /* member "certificate" */
167  if (p_struct->certificate) {
168  GWEN_Buffer_free(p_struct->certificate);
169  p_struct->certificate=NULL;
170  p_struct->certificate=NULL;
171  }
172  if (p_src->certificate) {
173  p_struct->certificate=GWEN_Buffer_dup(p_src->certificate);
174  }
175 
176  /* member "certType" */
177  p_struct->certType=p_src->certType;
178 
179  return p_struct;
180 }
181 
183  const GWEN_CRYPT_TOKEN_KEYINFO *p_src)
184 {
185  assert(p_struct);
186  assert(p_src);
187  /* member "id" */
188  p_struct->id=p_src->id;
189 
190  /* member "keyDescr" */
191  if (p_struct->keyDescr) {
192  free(p_struct->keyDescr);
193  p_struct->keyDescr=NULL;
194  p_struct->keyDescr=NULL;
195  }
196  if (p_src->keyDescr) {
197  p_struct->keyDescr=strdup(p_src->keyDescr);
198  }
199 
200  /* member "flags" */
201  p_struct->flags=p_src->flags;
202 
203  /* member "keySize" */
204  p_struct->keySize=p_src->keySize;
205 
206  /* member "cryptAlgoId" */
207  p_struct->cryptAlgoId=p_src->cryptAlgoId;
208 
209  /* member "modulus" */
210  if (p_struct->modulus) {
211  GWEN_Buffer_free(p_struct->modulus);
212  p_struct->modulus=NULL;
213  p_struct->modulus=NULL;
214  }
215  if (p_src->modulus) {
216  p_struct->modulus=GWEN_Buffer_dup(p_src->modulus);
217  }
218 
219  /* member "exponent" */
220  if (p_struct->exponent) {
221  GWEN_Buffer_free(p_struct->exponent);
222  p_struct->exponent=NULL;
223  p_struct->exponent=NULL;
224  }
225  if (p_src->exponent) {
226  p_struct->exponent=GWEN_Buffer_dup(p_src->exponent);
227  }
228 
229  /* member "keyNumber" */
230  p_struct->keyNumber=p_src->keyNumber;
231 
232  /* member "keyVersion" */
233  p_struct->keyVersion=p_src->keyVersion;
234 
235  /* member "signCounter" */
236  p_struct->signCounter=p_src->signCounter;
237 
238  /* member "certificate" */
239  if (p_struct->certificate) {
240  GWEN_Buffer_free(p_struct->certificate);
241  p_struct->certificate=NULL;
242  p_struct->certificate=NULL;
243  }
244  if (p_src->certificate) {
245  p_struct->certificate=GWEN_Buffer_dup(p_src->certificate);
246  }
247 
248  /* member "certType" */
249  p_struct->certType=p_src->certType;
250 
251  return p_struct;
252 }
253 
255 {
256  assert(p_struct);
257  return p_struct->id;
258 }
259 
261 {
262  assert(p_struct);
263  return p_struct->keyDescr;
264 }
265 
267 {
268  assert(p_struct);
269  return p_struct->flags;
270 }
271 
273 {
274  assert(p_struct);
275  return p_struct->keySize;
276 }
277 
279 {
280  assert(p_struct);
281  return p_struct->cryptAlgoId;
282 }
283 
285 {
286  assert(p_struct);
287  return p_struct->keyNumber;
288 }
289 
291 {
292  assert(p_struct);
293  return p_struct->keyVersion;
294 }
295 
297 {
298  assert(p_struct);
299  return p_struct->signCounter;
300 }
301 
303 {
304  assert(p_struct);
305  return p_struct->certType;
306 }
307 
309 {
310  assert(p_struct);
311  p_struct->id=p_src;
312 }
313 
315 {
316  assert(p_struct);
317  if (p_struct->keyDescr) {
318  free(p_struct->keyDescr);
319  p_struct->keyDescr=NULL;
320  }
321  if (p_src) {
322  p_struct->keyDescr=strdup(p_src);
323  }
324  else {
325  p_struct->keyDescr=NULL;
326  }
327 }
328 
330 {
331  assert(p_struct);
332  p_struct->flags=p_src;
333 }
334 
336 {
337  assert(p_struct);
338  p_struct->flags|=p_src;
339 }
340 
342 {
343  assert(p_struct);
344  p_struct->flags&=~p_src;
345 }
346 
348 {
349  assert(p_struct);
350  p_struct->keySize=p_src;
351 }
352 
354 {
355  assert(p_struct);
356  p_struct->cryptAlgoId=p_src;
357 }
358 
360 {
361  assert(p_struct);
362  p_struct->keyNumber=p_src;
363 }
364 
366 {
367  assert(p_struct);
368  p_struct->keyVersion=p_src;
369 }
370 
372 {
373  assert(p_struct);
374  p_struct->signCounter=p_src;
375 }
376 
378 {
379  assert(p_struct);
380  p_struct->certType=p_src;
381 }
382 
383 /* list1 functions */
385 {
387  GWEN_CRYPT_TOKEN_KEYINFO *p_elem;
388 
389  assert(p_src);
392  while (p_elem) {
394 
395  p_cpy=GWEN_Crypt_Token_KeyInfo_dup(p_elem);
396  GWEN_Crypt_Token_KeyInfo_List_Add(p_cpy, p_dest);
397  p_elem=GWEN_Crypt_Token_KeyInfo_List_Next(p_elem);
398  }
399 
400  return p_dest;
401 }
402 
404 {
405  assert(p_struct);
406  /* member "id" */
407  p_struct->id=GWEN_DB_GetIntValue(p_db, "id", 0, 0);
408 
409  /* member "keyDescr" */
410  if (p_struct->keyDescr) {
411  free(p_struct->keyDescr);
412  p_struct->keyDescr=NULL;
413  }
414  {
415  const char *s;
416  s=GWEN_DB_GetCharValue(p_db, "keyDescr", 0, NULL);
417  if (s)
418  p_struct->keyDescr=strdup(s);
419  }
420  if (p_struct->keyDescr==NULL) {
421  p_struct->keyDescr=NULL;
422  }
423 
424  /* member "flags" */
425  p_struct->flags=GWEN_DB_GetIntValue(p_db, "flags", 0, 0);
426 
427  /* member "keySize" */
428  p_struct->keySize=GWEN_DB_GetIntValue(p_db, "keySize", 0, 0);
429 
430  /* member "cryptAlgoId" */
431  p_struct->cryptAlgoId=GWEN_DB_GetIntValue(p_db, "cryptAlgoId", 0, 0);
432 
433  /* member "modulus" */
434  if (p_struct->modulus) {
435  GWEN_Buffer_free(p_struct->modulus);
436  p_struct->modulus=NULL;
437  }
438  {
439  const uint8_t *ptr;
440  uint32_t len;
441  ptr=GWEN_DB_GetBinValue(p_db, "modulus", 0, NULL, 0, &len);
442  if (ptr && len) {
443  p_struct->modulus=GWEN_Buffer_new(0, len, 0, 1);
444  GWEN_Buffer_AppendBytes(p_struct->modulus, (const char *)ptr, len);
445  }
446  }
447  if (p_struct->modulus==NULL) {
448  p_struct->modulus=NULL;
449  }
450 
451  /* member "exponent" */
452  if (p_struct->exponent) {
453  GWEN_Buffer_free(p_struct->exponent);
454  p_struct->exponent=NULL;
455  }
456  {
457  const uint8_t *ptr;
458  uint32_t len;
459  ptr=GWEN_DB_GetBinValue(p_db, "exponent", 0, NULL, 0, &len);
460  if (ptr && len) {
461  p_struct->exponent=GWEN_Buffer_new(0, len, 0, 1);
462  GWEN_Buffer_AppendBytes(p_struct->exponent, (const char *)ptr, len);
463  }
464  }
465  if (p_struct->exponent==NULL) {
466  p_struct->exponent=NULL;
467  }
468 
469  /* member "keyNumber" */
470  p_struct->keyNumber=GWEN_DB_GetIntValue(p_db, "keyNumber", 0, 0);
471 
472  /* member "keyVersion" */
473  p_struct->keyVersion=GWEN_DB_GetIntValue(p_db, "keyVersion", 0, 0);
474 
475  /* member "signCounter" */
476  p_struct->signCounter=GWEN_DB_GetIntValue(p_db, "signCounter", 0, 0);
477 
478  /* member "certificate" */
479  if (p_struct->certificate) {
480  GWEN_Buffer_free(p_struct->certificate);
481  p_struct->certificate=NULL;
482  }
483  {
484  const uint8_t *ptr;
485  uint32_t len;
486  ptr=GWEN_DB_GetBinValue(p_db, "certificate", 0, NULL, 0, &len);
487  if (ptr && len) {
488  p_struct->certificate=GWEN_Buffer_new(0, len, 0, 1);
489  GWEN_Buffer_AppendBytes(p_struct->certificate, (const char *)ptr, len);
490  }
491  }
492  if (p_struct->certificate==NULL) {
493  p_struct->certificate=NULL;
494  }
495 
496  /* member "certType" */
497  p_struct->certType=GWEN_DB_GetIntValue(p_db, "certType", 0, 0);
498 
499 }
500 
502 {
503  int p_rv;
504 
505  assert(p_struct);
506  /* member "id" */
507  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "id", p_struct->id);
508  if (p_rv<0) {
509  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
510  return p_rv;
511  }
512 
513  /* member "keyDescr" */
514  if (p_struct->keyDescr)
515  p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "keyDescr", p_struct->keyDescr);
516  else {
517  GWEN_DB_DeleteVar(p_db, "keyDescr");
518  p_rv=0;
519  }
520  if (p_rv<0) {
521  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
522  return p_rv;
523  }
524 
525  /* member "flags" */
526  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "flags", p_struct->flags);
527  if (p_rv<0) {
528  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
529  return p_rv;
530  }
531 
532  /* member "keySize" */
533  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "keySize", p_struct->keySize);
534  if (p_rv<0) {
535  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
536  return p_rv;
537  }
538 
539  /* member "cryptAlgoId" */
540  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "cryptAlgoId", p_struct->cryptAlgoId);
541  if (p_rv<0) {
542  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
543  return p_rv;
544  }
545 
546  /* member "modulus" */
547  if (p_struct->modulus)
548  p_rv=GWEN_DB_SetBinValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "modulus", GWEN_Buffer_GetStart(p_struct->modulus),
549  GWEN_Buffer_GetUsedBytes(p_struct->modulus));
550  else {
551  GWEN_DB_DeleteVar(p_db, "modulus");
552  p_rv=0;
553  }
554  if (p_rv<0) {
555  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
556  return p_rv;
557  }
558 
559  /* member "exponent" */
560  if (p_struct->exponent)
561  p_rv=GWEN_DB_SetBinValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "exponent", GWEN_Buffer_GetStart(p_struct->exponent),
562  GWEN_Buffer_GetUsedBytes(p_struct->exponent));
563  else {
564  GWEN_DB_DeleteVar(p_db, "exponent");
565  p_rv=0;
566  }
567  if (p_rv<0) {
568  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
569  return p_rv;
570  }
571 
572  /* member "keyNumber" */
573  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "keyNumber", p_struct->keyNumber);
574  if (p_rv<0) {
575  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
576  return p_rv;
577  }
578 
579  /* member "keyVersion" */
580  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "keyVersion", p_struct->keyVersion);
581  if (p_rv<0) {
582  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
583  return p_rv;
584  }
585 
586  /* member "signCounter" */
587  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "signCounter", p_struct->signCounter);
588  if (p_rv<0) {
589  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
590  return p_rv;
591  }
592 
593  /* member "certificate" */
594  if (p_struct->certificate)
595  p_rv=GWEN_DB_SetBinValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "certificate", GWEN_Buffer_GetStart(p_struct->certificate),
596  GWEN_Buffer_GetUsedBytes(p_struct->certificate));
597  else {
598  GWEN_DB_DeleteVar(p_db, "certificate");
599  p_rv=0;
600  }
601  if (p_rv<0) {
602  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
603  return p_rv;
604  }
605 
606  /* member "certType" */
607  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "certType", p_struct->certType);
608  if (p_rv<0) {
609  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
610  return p_rv;
611  }
612 
613  return 0;
614 }
615 
617 {
618  GWEN_CRYPT_TOKEN_KEYINFO *p_struct;
620  GWEN_Crypt_Token_KeyInfo_ReadDb(p_struct, p_db);
621  return p_struct;
622 }
623 
625 {
626  return GWEN_Crypt_Token_KeyInfo_WriteDb(p_struct, p_db);
627 }
628 
630 {
631  assert(p_struct);
632  /* member "id" */
633  p_struct->id=GWEN_XMLNode_GetIntValue(p_db, "id", 0);
634 
635  /* member "keyDescr" */
636  if (p_struct->keyDescr) {
637  free(p_struct->keyDescr);
638  p_struct->keyDescr=NULL;
639  }
640  {
641  const char *s;
642  s=GWEN_XMLNode_GetCharValue(p_db, "keyDescr", NULL);
643  if (s)
644  p_struct->keyDescr=strdup(s);
645  }
646  if (p_struct->keyDescr==NULL) { /* preset member "keyDescr" if empty */
647  p_struct->keyDescr=NULL;
648  }
649 
650  /* member "flags" */
651  p_struct->flags=GWEN_XMLNode_GetIntValue(p_db, "flags", 0);
652 
653  /* member "keySize" */
654  p_struct->keySize=GWEN_XMLNode_GetIntValue(p_db, "keySize", 0);
655 
656  /* member "cryptAlgoId" */
657  p_struct->cryptAlgoId=GWEN_XMLNode_GetIntValue(p_db, "cryptAlgoId", 0);
658 
659  /* member "modulus" */
660  if (p_struct->modulus) {
661  GWEN_Buffer_free(p_struct->modulus);
662  p_struct->modulus=NULL;
663  }
664  {
665  const char *s;
666  s=GWEN_XMLNode_GetCharValue(p_db, "modulus", NULL);
667  if (s) {
668  p_struct->modulus=GWEN_Buffer_new(0, strlen(s)/2, 0, 1);
669  GWEN_Text_FromHexBuffer(s, p_struct->modulus);
670  }
671  }
672  if (p_struct->modulus==NULL) { /* preset member "modulus" if empty */
673  p_struct->modulus=NULL;
674  }
675 
676  /* member "exponent" */
677  if (p_struct->exponent) {
678  GWEN_Buffer_free(p_struct->exponent);
679  p_struct->exponent=NULL;
680  }
681  {
682  const char *s;
683  s=GWEN_XMLNode_GetCharValue(p_db, "exponent", NULL);
684  if (s) {
685  p_struct->exponent=GWEN_Buffer_new(0, strlen(s)/2, 0, 1);
686  GWEN_Text_FromHexBuffer(s, p_struct->exponent);
687  }
688  }
689  if (p_struct->exponent==NULL) { /* preset member "exponent" if empty */
690  p_struct->exponent=NULL;
691  }
692 
693  /* member "keyNumber" */
694  p_struct->keyNumber=GWEN_XMLNode_GetIntValue(p_db, "keyNumber", 0);
695 
696  /* member "keyVersion" */
697  p_struct->keyVersion=GWEN_XMLNode_GetIntValue(p_db, "keyVersion", 0);
698 
699  /* member "signCounter" */
700  p_struct->signCounter=GWEN_XMLNode_GetIntValue(p_db, "signCounter", 0);
701 
702  /* member "certificate" */
703  if (p_struct->certificate) {
704  GWEN_Buffer_free(p_struct->certificate);
705  p_struct->certificate=NULL;
706  }
707  {
708  const char *s;
709  s=GWEN_XMLNode_GetCharValue(p_db, "certificate", NULL);
710  if (s) {
711  p_struct->certificate=GWEN_Buffer_new(0, strlen(s)/2, 0, 1);
712  GWEN_Text_FromHexBuffer(s, p_struct->certificate);
713  }
714  }
715  if (p_struct->certificate==NULL) { /* preset member "certificate" if empty */
716  p_struct->certificate=NULL;
717  }
718 
719  /* member "certType" */
720  p_struct->certType=GWEN_XMLNode_GetIntValue(p_db, "certType", 0);
721 
722 }
723 
725 {
726  assert(p_struct);
727  /* member "id" */
728  GWEN_XMLNode_SetIntValue(p_db, "id", p_struct->id);
729 
730  /* member "keyDescr" */
731  GWEN_XMLNode_SetCharValue(p_db, "keyDescr", p_struct->keyDescr);
732 
733  /* member "flags" */
734  GWEN_XMLNode_SetIntValue(p_db, "flags", p_struct->flags);
735 
736  /* member "keySize" */
737  GWEN_XMLNode_SetIntValue(p_db, "keySize", p_struct->keySize);
738 
739  /* member "cryptAlgoId" */
740  GWEN_XMLNode_SetIntValue(p_db, "cryptAlgoId", p_struct->cryptAlgoId);
741 
742  /* member "modulus" */
743  if (p_struct->modulus) {
744  GWEN_BUFFER *tbuf;
745  tbuf=GWEN_Buffer_new(0, GWEN_Buffer_GetUsedBytes(p_struct->modulus)*2, 0, 1);
746  GWEN_Text_ToHexBuffer(GWEN_Buffer_GetStart(p_struct->modulus), GWEN_Buffer_GetUsedBytes(p_struct->modulus), tbuf, 0, 0,
747  0);
748  GWEN_XMLNode_SetCharValue(p_db, "modulus", GWEN_Buffer_GetStart(tbuf));
749  GWEN_Buffer_free(tbuf);
750  }
751 
752  /* member "exponent" */
753  if (p_struct->exponent) {
754  GWEN_BUFFER *tbuf;
755  tbuf=GWEN_Buffer_new(0, GWEN_Buffer_GetUsedBytes(p_struct->exponent)*2, 0, 1);
756  GWEN_Text_ToHexBuffer(GWEN_Buffer_GetStart(p_struct->exponent), GWEN_Buffer_GetUsedBytes(p_struct->exponent), tbuf, 0,
757  0, 0);
758  GWEN_XMLNode_SetCharValue(p_db, "exponent", GWEN_Buffer_GetStart(tbuf));
759  GWEN_Buffer_free(tbuf);
760  }
761 
762  /* member "keyNumber" */
763  GWEN_XMLNode_SetIntValue(p_db, "keyNumber", p_struct->keyNumber);
764 
765  /* member "keyVersion" */
766  GWEN_XMLNode_SetIntValue(p_db, "keyVersion", p_struct->keyVersion);
767 
768  /* member "signCounter" */
769  GWEN_XMLNode_SetIntValue(p_db, "signCounter", p_struct->signCounter);
770 
771  /* member "certificate" */
772  if (p_struct->certificate) {
773  GWEN_BUFFER *tbuf;
774  tbuf=GWEN_Buffer_new(0, GWEN_Buffer_GetUsedBytes(p_struct->certificate)*2, 0, 1);
775  GWEN_Text_ToHexBuffer(GWEN_Buffer_GetStart(p_struct->certificate), GWEN_Buffer_GetUsedBytes(p_struct->certificate),
776  tbuf, 0, 0, 0);
777  GWEN_XMLNode_SetCharValue(p_db, "certificate", GWEN_Buffer_GetStart(tbuf));
778  GWEN_Buffer_free(tbuf);
779  }
780 
781  /* member "certType" */
782  GWEN_XMLNode_SetIntValue(p_db, "certType", p_struct->certType);
783 
784 }
785 
787 {
788  GWEN_Crypt_Token_KeyInfo_WriteXml(p_struct, p_db);
789 }
790 
792 {
793  GWEN_CRYPT_TOKEN_KEYINFO *p_struct;
795  GWEN_Crypt_Token_KeyInfo_ReadXml(p_struct, p_db);
796  return p_struct;
797 }
798 
800  uint32_t p_cmp)
801 {
802  GWEN_CRYPT_TOKEN_KEYINFO *p_struct;
803 
804  assert(p_list);
805  p_struct = GWEN_Crypt_Token_KeyInfo_List_First(p_list);
806  while (p_struct) {
807  int p_rv;
808 
809  if (p_struct->id==p_cmp)
810  p_rv=0;
811  else if (p_cmp<p_struct->id)
812  p_rv=-1;
813  else
814  p_rv=1;
815  if (p_rv == 0)
816  return p_struct;
817  p_struct = GWEN_Crypt_Token_KeyInfo_List_Next(p_struct);
818  }
819  return NULL;
820 }
821 
823 {
826  ki->id=kid;
827  ki->cryptAlgoId=a;
828  ki->keySize=keySize;
829  return ki;
830 }
831 void GWEN_Crypt_Token_KeyInfo_SetModulus(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
832 {
833  assert(st);
834  if (st->modulus)
835  GWEN_Buffer_free(st->modulus);
836  if (p && len) {
837  st->modulus=GWEN_Buffer_new(0, len, 0, 1);
838  GWEN_Buffer_AppendBytes(st->modulus, (const char *) p, len);
839  }
840  else
841  st->modulus=NULL;
842 }
844 {
845  assert(st);
846  if (st->modulus)
847  return (const uint8_t *) GWEN_Buffer_GetStart(st->modulus);
848  else
849  return NULL;
850 }
852 {
853  assert(st);
854  if (st->modulus)
855  return GWEN_Buffer_GetUsedBytes(st->modulus);
856  else
857  return 0;
858 }
859 void GWEN_Crypt_Token_KeyInfo_SetExponent(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
860 {
861  assert(st);
862  if (st->exponent)
863  GWEN_Buffer_free(st->exponent);
864  if (p && len) {
865  st->exponent=GWEN_Buffer_new(0, len, 0, 1);
866  GWEN_Buffer_AppendBytes(st->exponent, (const char *) p, len);
867  }
868  else
869  st->exponent=NULL;
870 }
872 {
873  assert(st);
874  if (st->exponent)
875  return (const uint8_t *) GWEN_Buffer_GetStart(st->exponent);
876  else
877  return NULL;
878 }
880 {
881  assert(st);
882  if (st->exponent)
883  return GWEN_Buffer_GetUsedBytes(st->exponent);
884  else
885  return 0;
886 }
887 void GWEN_Crypt_Token_KeyInfo_SetCertificate(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
888 {
889  assert(st);
890  if (st->certificate)
891  GWEN_Buffer_free(st->certificate);
892  if (p && len) {
893  st->certificate=GWEN_Buffer_new(0, len, 0, 1);
894  GWEN_Buffer_AppendBytes(st->certificate, (const char *) p, len);
895  }
896  else
897  st->certificate=NULL;
898 }
900 {
901  assert(st);
902  if (st->certificate)
903  return (const uint8_t *) GWEN_Buffer_GetStart(st->certificate);
904  else
905  return NULL;
906 }
908 {
909  assert(st);
910  if (st->certificate)
911  return GWEN_Buffer_GetUsedBytes(st->certificate);
912  else
913  return 0;
914 }
915 
916 /* code headers */
917 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
#define GWEN_LIST2_FUNCTIONS(t, pr)
Definition: list2.h:99
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define GWEN_INHERIT_FINI(t, element)
Definition: inherit.h:238
const uint8_t * GWEN_Crypt_Token_KeyInfo_GetModulusData(const GWEN_CRYPT_TOKEN_KEYINFO *st)
Definition: ct_keyinfo.c:843
void GWEN_Crypt_Token_KeyInfo_SetCertificate(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
Definition: ct_keyinfo.c:887
uint32_t GWEN_Crypt_Token_KeyInfo_GetId(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:254
void GWEN_Crypt_Token_KeyInfo_free(GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:78
void GWEN_Crypt_Token_KeyInfo_Attach(GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:102
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
Definition: buffer.c:277
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo__new(void)
Definition: ct_keyinfo.c:52
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
void GWEN_Crypt_Token_KeyInfo_SetModulus(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
Definition: ct_keyinfo.c:831
GWEN_CRYPT_TOKEN_KEYINFO_LIST * GWEN_Crypt_Token_KeyInfo_List_dup(const GWEN_CRYPT_TOKEN_KEYINFO_LIST *p_src)
Definition: ct_keyinfo.c:384
void GWEN_XMLNode_SetCharValue(GWEN_XMLNODE *n, const char *name, const char *value)
Definition: xml.c:897
#define GWEN_LOGDOMAIN
Definition: logger.h:35
uint32_t GWEN_Crypt_Token_KeyInfo_GetCertificateLen(const GWEN_CRYPT_TOKEN_KEYINFO *st)
Definition: ct_keyinfo.c:907
void GWEN_Crypt_Token_KeyInfo_toXml(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_XMLNODE *p_db)
Definition: ct_keyinfo.c:786
uint32_t GWEN_Crypt_Token_KeyInfo_GetSignCounter(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:296
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_List_GetById(const GWEN_CRYPT_TOKEN_KEYINFO_LIST *p_list, uint32_t p_cmp)
Definition: ct_keyinfo.c:799
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
int GWEN_XMLNode_GetIntValue(const GWEN_XMLNODE *n, const char *name, int defValue)
Definition: xml.c:923
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_dup(const GWEN_CRYPT_TOKEN_KEYINFO *p_src)
Definition: ct_keyinfo.c:109
uint32_t GWEN_Crypt_Token_KeyInfo_GetModulusLen(const GWEN_CRYPT_TOKEN_KEYINFO *st)
Definition: ct_keyinfo.c:851
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_copy(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, const GWEN_CRYPT_TOKEN_KEYINFO *p_src)
Definition: ct_keyinfo.c:182
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)
Definition: db.c:1269
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
GWEN_CRYPT_TOKEN_KEYSTATUS
Definition: ct_keyinfo.h:134
uint32_t GWEN_Crypt_Token_KeyInfo_GetKeyVersion(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:290
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_fromDb(GWEN_DB_NODE *p_db)
Definition: ct_keyinfo.c:616
GWEN_CRYPT_CRYPTALGOID
Definition: cryptalgo.h:52
const char * GWEN_XMLNode_GetCharValue(const GWEN_XMLNODE *n, const char *name, const char *defValue)
Definition: xml.c:812
int GWEN_Crypt_Token_KeyInfo_GetKeySize(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:272
const uint8_t * GWEN_Crypt_Token_KeyInfo_GetExponentData(const GWEN_CRYPT_TOKEN_KEYINFO *st)
Definition: ct_keyinfo.c:871
void GWEN_Crypt_Token_KeyInfo_SetKeyVersion(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:365
const void * GWEN_DB_GetBinValue(GWEN_DB_NODE *n, const char *path, int idx, const void *defVal, unsigned int defValSize, unsigned int *returnValueSize)
Definition: db.c:1237
const char * GWEN_Crypt_Token_KeyStatus_toString(GWEN_CRYPT_TOKEN_KEYSTATUS p_i)
Definition: ct_keyinfo.c:38
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:971
uint32_t GWEN_Crypt_Token_KeyInfo_GetFlags(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:266
#define GWEN_INHERIT_INIT(t, element)
Definition: inherit.h:223
int GWEN_Crypt_Token_KeyInfo_GetCryptAlgoId(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:278
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)
Definition: ct_keyinfo.c:353
GWEN_BUFFER * GWEN_Buffer_dup(GWEN_BUFFER *bf)
Definition: buffer.c:105
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
int GWEN_DB_DeleteVar(GWEN_DB_NODE *n, const char *path)
Definition: db.c:899
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
void GWEN_Crypt_Token_KeyInfo_SetCertType(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint8_t p_src)
Definition: ct_keyinfo.c:377
GWEN_CRYPT_TOKEN_KEYSTATUS GWEN_Crypt_Token_KeyStatus_fromString(const char *p_s)
Definition: ct_keyinfo.c:25
const char * GWEN_Crypt_Token_KeyInfo_GetKeyDescr(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:260
struct GWEN_CRYPT_TOKEN_KEYINFO GWEN_CRYPT_TOKEN_KEYINFO
Definition: ct_keyinfo.h:127
int GWEN_Crypt_Token_KeyInfo_toDb(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_DB_NODE *p_db)
Definition: ct_keyinfo.c:624
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)
Definition: db.c:997
uint8_t GWEN_Crypt_Token_KeyInfo_GetCertType(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:302
void GWEN_Crypt_Token_KeyInfo_SetExponent(GWEN_CRYPT_TOKEN_KEYINFO *st, const uint8_t *p, uint32_t len)
Definition: ct_keyinfo.c:859
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:181
void GWEN_Crypt_Token_KeyInfo_WriteXml(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_XMLNODE *p_db)
Definition: ct_keyinfo.c:724
void GWEN_Crypt_Token_KeyInfo_SetFlags(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:329
uint32_t GWEN_Crypt_Token_KeyInfo_GetExponentLen(const GWEN_CRYPT_TOKEN_KEYINFO *st)
Definition: ct_keyinfo.c:879
void GWEN_Crypt_Token_KeyInfo_SetKeyNumber(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:359
#define GWEN_LIST_INIT(t, element)
Definition: list1.h:465
void GWEN_Crypt_Token_KeyInfo_ReadDb(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_DB_NODE *p_db)
Definition: ct_keyinfo.c:403
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_new(uint32_t kid, GWEN_CRYPT_CRYPTALGOID a, int keySize)
Definition: ct_keyinfo.c:822
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1163
void GWEN_Crypt_Token_KeyInfo_SetSignCounter(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:371
void GWEN_Crypt_Token_KeyInfo_SubFlags(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:341
int GWEN_Buffer_AppendBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
Definition: buffer.c:361
void GWEN_Crypt_Token_KeyInfo_ReadXml(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_XMLNODE *p_db)
Definition: ct_keyinfo.c:629
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1202
#define GWEN_LIST_FUNCTIONS(t, pr)
Definition: list1.h:366
void GWEN_Crypt_Token_KeyInfo_SetKeySize(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, int p_src)
Definition: ct_keyinfo.c:347
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_fromXml(GWEN_XMLNODE *p_db)
Definition: ct_keyinfo.c:791
void GWEN_Crypt_Token_KeyInfo_SetId(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:308
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)
Definition: text.c:897
void GWEN_Crypt_Token_KeyInfo_SetKeyDescr(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, const char *p_src)
Definition: ct_keyinfo.c:314
#define GWEN_LIST_FINI(t, element)
Definition: list1.h:474
#define GWEN_INHERIT_FUNCTIONS(t)
Definition: inherit.h:163
int GWEN_Text_ToHexBuffer(const char *src, unsigned l, GWEN_BUFFER *buf, unsigned int groupsize, char delimiter, int skipLeadingZeroes)
Definition: text.c:777
struct GWEN__XMLNODE GWEN_XMLNODE
Definition: xml.h:156
uint32_t GWEN_Crypt_Token_KeyInfo_GetKeyNumber(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:284
void GWEN_Crypt_Token_KeyInfo_AddFlags(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:335
void GWEN_XMLNode_SetIntValue(GWEN_XMLNODE *n, const char *name, int value)
Definition: xml.c:940
int GWEN_Crypt_Token_KeyInfo_WriteDb(const GWEN_CRYPT_TOKEN_KEYINFO *p_struct, GWEN_DB_NODE *p_db)
Definition: ct_keyinfo.c:501
const uint8_t * GWEN_Crypt_Token_KeyInfo_GetCertificateData(const GWEN_CRYPT_TOKEN_KEYINFO *st)
Definition: ct_keyinfo.c:899