Skip to content

Commit 645460a

Browse files
committed
add pk_oid_cmp_with_asn1()
1 parent e318f6f commit 645460a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/headers/tomcrypt_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
303303
unsigned int algorithm, void* public_key, unsigned long* public_key_len,
304304
ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len);
305305

306+
int pk_oid_cmp_with_asn1(const char *o1, const ltc_asn1_list *o2);
307+
306308
#endif /* LTC_DER */
307309

308310
/* tomcrypt_pkcs.h */

src/pk/asn1/oid/pk_oid_asn1.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* guarantee it works.
8+
*/
9+
#include "tomcrypt_private.h"
10+
11+
#ifdef LTC_DER
12+
13+
/*
14+
Compare an OID string to an OID element decoded from ASN.1.
15+
@return CRYPT_OK if equal
16+
*/
17+
int pk_oid_cmp_with_asn1(const char *o1, const ltc_asn1_list *o2)
18+
{
19+
unsigned long i;
20+
char tmp[256] = { 0 };
21+
int err;
22+
23+
if (o1 == NULL || o2 == NULL) return CRYPT_ERROR;
24+
25+
if (o2->type != LTC_ASN1_OBJECT_IDENTIFIER) return CRYPT_INVALID_ARG;
26+
27+
i = sizeof(tmp);
28+
if ((err = pk_oid_num_to_str(o2->data, o2->size, tmp, &i)) != CRYPT_OK) {
29+
return err;
30+
}
31+
32+
if (XSTRCMP(o1, tmp) != 0) {
33+
return CRYPT_PK_INVALID_TYPE;
34+
}
35+
36+
return CRYPT_OK;
37+
}
38+
39+
#endif
40+
41+
/* ref: $Format:%D$ */
42+
/* git commit: $Format:%H$ */
43+
/* commit time: $Format:%ai$ */

0 commit comments

Comments
 (0)