Debian Codegraph @

src/ltc/pk/asn1/x509/x509_get_pka.c

raw symbols SCIP
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 /**
6 @file x509_get_pka.c
7 Extract the PKA from an X.509 cert, Steffen Jaeckel
8 */
9
10 #ifdef LTC_DER
11
12 int x509_get_pka(const ltc_asn1_list *pub, enum ltc_pka_id *pka)
13 {
14 der_flexi_check flexi_should[4];
15 ltc_asn1_list *seqid, *id = NULL;
16 enum ltc_oid_id oid_id;
17 int err;
18 unsigned long n = 0;
19 LTC_SET_DER_FLEXI_CHECK(flexi_should, n++, LTC_ASN1_SEQUENCE, &seqid);
20 LTC_SET_DER_FLEXI_CHECK_OPT(flexi_should, n++, LTC_ASN1_BIT_STRING, NULL);
21 LTC_SET_DER_FLEXI_CHECK(flexi_should, n, LTC_ASN1_EOL, NULL);
22 if ((err = der_flexi_sequence_cmp(pub, flexi_should)) != CRYPT_OK) {
23 return err;
24 }
25 n = 0;
26 LTC_SET_DER_FLEXI_CHECK(flexi_should, n++, LTC_ASN1_OBJECT_IDENTIFIER, &id);
27 LTC_SET_DER_FLEXI_CHECK(flexi_should, n, LTC_ASN1_EOL, NULL);
28 err = der_flexi_sequence_cmp(seqid, flexi_should);
29 if (err != CRYPT_OK && err != CRYPT_INPUT_TOO_LONG) {
30 return err;
31 }
32 if ((err = pk_get_oid_from_asn1(id, &oid_id)) != CRYPT_OK) {
33 return err;
34 }
35 return pk_get_pka_id(oid_id, pka);
36 }
37
38 #endif /* LTC_DER */