@@ -352,19 +352,40 @@ struct bufp {
352352};
353353
354354#define SET_BUFP (n , d , l ) n.start = (char*)d, n.work = (char*)d, n.end = (char*)d + l + 1
355+ #define UPDATE_BUFP (n , d , w , l ) n.start = (char*)d, n.work = (char*)d + w, n.end = (char*)d + l + 1
355356
356- struct get_char {
357+ struct get_char ;
358+ struct get_char_api {
357359 int (* get )(struct get_char * );
360+ };
361+
362+ struct get_char {
363+ struct get_char_api api ;
358364 union {
359365#ifndef LTC_NO_FILE
360- FILE * f ;
366+ struct {
367+ FILE * f ;
368+ } f ;
361369#endif /* LTC_NO_FILE */
362370 struct bufp buf ;
363371 } data ;
364372 struct str unget_buf ;
365373 char unget_buf_ [LTC_PEM_DECODE_BUFSZ ];
366374 int prev_get ;
375+ unsigned long total_read ;
367376};
377+
378+ #define pem_get_char_init (b , l ) { \
379+ .api = get_char_buffer_api, \
380+ SET_BUFP(.data.buf, (b), (l)), \
381+ .total_read = 0, \
382+ }
383+
384+ #define pem_get_char_init_filehandle (fi ) { \
385+ .api = get_char_filehandle_api, \
386+ .data.f.f = (fi), \
387+ .total_read = 0, \
388+ }
368389#endif
369390
370391/* others */
@@ -387,10 +408,10 @@ int pem_decrypt(unsigned char *data, unsigned long *datalen,
387408 const struct blockcipher_info * info ,
388409 enum padding_type padding );
389410#ifndef LTC_NO_FILE
390- int pem_get_char_from_file ( struct get_char * g ) ;
411+ extern const struct get_char_api get_char_filehandle_api ;
391412#endif /* LTC_NO_FILE */
392- int pem_get_char_from_buf ( struct get_char * g ) ;
393- int pem_read (void * asn1_cert , unsigned long * asn1_len , struct pem_headers * hdr , struct get_char * g );
413+ extern const struct get_char_api get_char_buffer_api ;
414+ int pem_read (void * * dest , unsigned long * len , struct pem_headers * hdr , struct get_char * g );
394415#endif
395416
396417/* tomcrypt_pk.h */
@@ -651,17 +672,29 @@ int der_printable_value_decode(int v);
651672
652673unsigned long der_utf8_charsize (const wchar_t c );
653674
654- typedef struct {
675+ typedef int (* der_flexi_handler )(const ltc_asn1_list * , void * );
676+
677+ typedef struct der_flexi_check {
655678 ltc_asn1_type t ;
679+ int optional ;
656680 ltc_asn1_list * * pp ;
681+ der_flexi_handler handler ;
682+ void * userdata ;
657683} der_flexi_check ;
658684
659- #define LTC_SET_DER_FLEXI_CHECK (list , index , Type , P ) \
660- do { \
661- int LTC_SDFC_temp##__LINE__ = (index); \
662- list[LTC_SDFC_temp##__LINE__].t = Type; \
663- list[LTC_SDFC_temp##__LINE__].pp = P; \
685+ #define LTC_PRIV_SET_DER_FLEXI_CHECK (list , index , Type , P , Opt , Hndl , Udata ) \
686+ do { \
687+ int LTC_SDFC_temp##__LINE__ = (index); \
688+ list[LTC_SDFC_temp##__LINE__].t = Type; \
689+ list[LTC_SDFC_temp##__LINE__].pp = P; \
690+ list[LTC_SDFC_temp##__LINE__].optional = Opt; \
691+ list[LTC_SDFC_temp##__LINE__].handler = (der_flexi_handler)Hndl; \
692+ list[LTC_SDFC_temp##__LINE__].userdata = Udata; \
664693 } while (0)
694+ #define LTC_SET_DER_FLEXI_CHECK (list , index , Type , P ) LTC_PRIV_SET_DER_FLEXI_CHECK(list, index, Type, P, 0, NULL, NULL)
695+ #define LTC_SET_DER_FLEXI_CHECK_OPT (list , index , Type , P ) LTC_PRIV_SET_DER_FLEXI_CHECK(list, index, Type, P, 1, NULL, NULL)
696+ #define LTC_SET_DER_FLEXI_HANDLER (list , index , Type , Hndl , Udata ) LTC_PRIV_SET_DER_FLEXI_CHECK(list, index, Type, NULL, 0, Hndl, Udata)
697+ #define LTC_SET_DER_FLEXI_HANDLER_OPT (list , index , Type , Hndl , Udata ) LTC_PRIV_SET_DER_FLEXI_CHECK(list, index, Type, NULL, 1, Hndl, Udata)
665698
666699
667700extern const ltc_asn1_type der_asn1_tag_to_type_map [];
@@ -697,6 +730,9 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
697730 enum ltc_oid_id algorithm , void * public_key , unsigned long * public_key_len ,
698731 ltc_asn1_type parameters_type , ltc_asn1_list * parameters , unsigned long * parameters_len );
699732
733+ int x509_get_pka (ltc_asn1_list * pub , enum ltc_pka_id * pka );
734+ int x509_import_spki (const unsigned char * asn1_cert , unsigned long asn1_len , ltc_pka_key * k , ltc_asn1_list * * root );
735+
700736int pk_oid_cmp_with_asn1 (const char * o1 , const ltc_asn1_list * o2 );
701737
702738#endif /* LTC_DER */
0 commit comments