diff options
| author | jsing <> | 2022-03-02 11:28:00 +0000 |
|---|---|---|
| committer | jsing <> | 2022-03-02 11:28:00 +0000 |
| commit | 82fb0381802967c4e0623e7f4bde8e684c08dbc6 (patch) | |
| tree | ef22bb60da9100fb77f57965fd90ea63a5b3733b /src/lib/libcrypto/objects/obj_dat.c | |
| parent | 3afe4b6f29d7548f490e80402e8bf0ef7229dac1 (diff) | |
| download | openbsd-82fb0381802967c4e0623e7f4bde8e684c08dbc6.tar.gz openbsd-82fb0381802967c4e0623e7f4bde8e684c08dbc6.tar.bz2 openbsd-82fb0381802967c4e0623e7f4bde8e684c08dbc6.zip | |
Rewrite ASN1_OBJECT content to ascii/text conversion.
Rewrite the ASN1_OBJECT content to ascii/text conversion code using CBB and
CBS. Currently there is a strange split with i2t_ASN1_OBJECT() calling
OBJ_obj2txt() which implements the conversion, while OBJ_txt2obj() calls
back into the misnamed a2d_ASN1_OBJECT() function. Move the conversion
code into asn1/a_object.c and have OBJ_txt2obj() call that instead.
ok inoguchi@ tb@
Diffstat (limited to 'src/lib/libcrypto/objects/obj_dat.c')
| -rw-r--r-- | src/lib/libcrypto/objects/obj_dat.c | 81 |
1 files changed, 5 insertions, 76 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 03e65f1dfe..786bed6c7a 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: obj_dat.c,v 1.47 2022/02/12 03:01:59 jsing Exp $ */ | 1 | /* $OpenBSD: obj_dat.c,v 1.48 2022/03/02 11:28:00 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 | * |
| @@ -524,83 +524,12 @@ OBJ_txt2obj(const char *s, int no_name) | |||
| 524 | } | 524 | } |
| 525 | 525 | ||
| 526 | int | 526 | int |
| 527 | OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | 527 | OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *aobj, int no_name) |
| 528 | { | 528 | { |
| 529 | int i, ret = 0, len, nid, first = 1; | 529 | if (aobj == NULL || aobj->data == NULL) |
| 530 | const unsigned char *p; | 530 | return 0; |
| 531 | uint64_t l; | ||
| 532 | |||
| 533 | /* Ensure that, at every state, |buf| is NUL-terminated. */ | ||
| 534 | if (buf_len > 0) | ||
| 535 | buf[0] = '\0'; | ||
| 536 | |||
| 537 | if ((a == NULL) || (a->data == NULL)) | ||
| 538 | goto err; | ||
| 539 | |||
| 540 | if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) { | ||
| 541 | const char *s; | ||
| 542 | s = OBJ_nid2ln(nid); | ||
| 543 | if (s == NULL) | ||
| 544 | s = OBJ_nid2sn(nid); | ||
| 545 | if (s) { | ||
| 546 | ret = strlcpy(buf, s, buf_len); | ||
| 547 | goto out; | ||
| 548 | } | ||
| 549 | } | ||
| 550 | |||
| 551 | len = a->length; | ||
| 552 | p = a->data; | ||
| 553 | |||
| 554 | while (len > 0) { | ||
| 555 | l = 0; | ||
| 556 | for (;;) { | ||
| 557 | unsigned char c = *p++; | ||
| 558 | len--; | ||
| 559 | if ((len == 0) && (c & 0x80)) | ||
| 560 | goto err; | ||
| 561 | l |= c & 0x7f; | ||
| 562 | if (!(c & 0x80)) | ||
| 563 | break; | ||
| 564 | if (l > (UINT64_MAX >> 7L)) | ||
| 565 | goto err; | ||
| 566 | l <<= 7L; | ||
| 567 | } | ||
| 568 | |||
| 569 | if (first) { | ||
| 570 | first = 0; | ||
| 571 | if (l >= 80) { | ||
| 572 | i = 2; | ||
| 573 | l -= 80; | ||
| 574 | } else { | ||
| 575 | i = (int)(l / 40); | ||
| 576 | l -= (long)(i * 40); | ||
| 577 | } | ||
| 578 | if (buf_len > 1) { | ||
| 579 | *buf++ = i + '0'; | ||
| 580 | *buf = '\0'; | ||
| 581 | buf_len--; | ||
| 582 | } | ||
| 583 | ret++; | ||
| 584 | } | ||
| 585 | |||
| 586 | i = snprintf(buf, buf_len, ".%llu", l); | ||
| 587 | if (i < 0) | ||
| 588 | goto err; | ||
| 589 | if (i >= buf_len) { | ||
| 590 | buf_len = 0; | ||
| 591 | } else { | ||
| 592 | buf += i; | ||
| 593 | buf_len -= i; | ||
| 594 | } | ||
| 595 | ret += i; | ||
| 596 | } | ||
| 597 | |||
| 598 | out: | ||
| 599 | return ret; | ||
| 600 | 531 | ||
| 601 | err: | 532 | return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, no_name); |
| 602 | ret = 0; | ||
| 603 | goto out; | ||
| 604 | } | 533 | } |
| 605 | 534 | ||
| 606 | int | 535 | int |
