summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_object.c
diff options
context:
space:
mode:
authorjsing <>2022-03-19 17:49:32 +0000
committerjsing <>2022-03-19 17:49:32 +0000
commitd46a632ca35d3f62b29f97c14868a75a30a0ea74 (patch)
treed6cf88609bfc19f0101b68dd40457a903ba5c53a /src/lib/libcrypto/asn1/a_object.c
parentee5ce96399d588340c4f57044a36ddb289fe2a7a (diff)
downloadopenbsd-d46a632ca35d3f62b29f97c14868a75a30a0ea74.tar.gz
openbsd-d46a632ca35d3f62b29f97c14868a75a30a0ea74.tar.bz2
openbsd-d46a632ca35d3f62b29f97c14868a75a30a0ea74.zip
Provide t2i_ASN1_OBJECT_internal() and use it for OBJ_txt2obj()
The current OBJ_txt2obj() implementation converts the text to ASN.1 object content octets, builds a full DER encoding from it, then feeds the entire thing back through the DER to ASN.1 object conversion. Rather than doing this crazy dance, provide an t2i_ASN1_OBJECT_internal() function that converts the text to ASN.1 object content octets, then creates a new ASN1_OBJECT and attaches the content octets to it. ok inoguchi@ tb@
Diffstat (limited to 'src/lib/libcrypto/asn1/a_object.c')
-rw-r--r--src/lib/libcrypto/asn1/a_object.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index 0061ccb880..56a08a3cb4 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_object.c,v 1.42 2022/03/19 17:35:52 jsing Exp $ */ 1/* $OpenBSD: a_object.c,v 1.43 2022/03/19 17:49:32 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -475,6 +475,43 @@ i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *aobj)
475 return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, 0); 475 return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, 0);
476} 476}
477 477
478ASN1_OBJECT *
479t2i_ASN1_OBJECT_internal(const char *oid)
480{
481 ASN1_OBJECT *aobj = NULL;
482 uint8_t *data = NULL;
483 size_t data_len;
484 CBB cbb;
485 CBS cbs;
486
487 memset(&cbb, 0, sizeof(cbb));
488
489 CBS_init(&cbs, oid, strlen(oid));
490
491 if (!CBB_init(&cbb, 0))
492 goto err;
493 if (!a2c_ASN1_OBJECT_internal(&cbb, &cbs))
494 goto err;
495 if (!CBB_finish(&cbb, &data, &data_len))
496 goto err;
497
498 if (data_len > INT_MAX)
499 goto err;
500
501 if ((aobj = ASN1_OBJECT_new()) == NULL)
502 goto err;
503
504 aobj->data = data;
505 aobj->length = (int)data_len;
506 data = NULL;
507
508 err:
509 CBB_cleanup(&cbb);
510 free(data);
511
512 return aobj;
513}
514
478int 515int
479i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *aobj) 516i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *aobj)
480{ 517{