Make obj2txt accept empty OIDs because Python depends on it.
Change-Id: I44bc5979cb8c15ad8c4f9bef17049312b6f23a41 Reviewed-on: https://boringssl-review.googlesource.com/10200 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: David Benjamin <davidben@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
f71d7ed014
commit
909232db55
@ -455,6 +455,12 @@ static int add_decimal(CBB *out, uint64_t v) {
|
||||
|
||||
int OBJ_obj2txt(char *out, int out_len, const ASN1_OBJECT *obj,
|
||||
int dont_return_name) {
|
||||
/* Python depends on the empty OID successfully encoding as the empty
|
||||
* string. */
|
||||
if (obj == NULL || obj->length == 0) {
|
||||
return strlcpy_int(out, "", out_len);
|
||||
}
|
||||
|
||||
if (!dont_return_name) {
|
||||
int nid = OBJ_obj2nid(obj);
|
||||
if (nid != NID_undef) {
|
||||
|
@ -95,8 +95,7 @@ static bool TestSignatureAlgorithms() {
|
||||
}
|
||||
|
||||
static bool ExpectObj2Txt(const uint8_t *der, size_t der_len,
|
||||
bool dont_return_name,
|
||||
const char *expected) {
|
||||
bool dont_return_name, const char *expected) {
|
||||
ASN1_OBJECT obj;
|
||||
memset(&obj, 0, sizeof(obj));
|
||||
obj.data = der;
|
||||
@ -178,18 +177,17 @@ static bool TestObj2Txt() {
|
||||
!ExpectObj2Txt(kTestOID, sizeof(kTestOID), true /* don't return name */,
|
||||
"1.2.840.113554.4.1.72585.0") ||
|
||||
!ExpectObj2Txt(kTestOID, sizeof(kTestOID), false /* return name */,
|
||||
"1.2.840.113554.4.1.72585.0")) {
|
||||
"1.2.840.113554.4.1.72585.0") ||
|
||||
// Python depends on the empty OID successfully encoding as the empty
|
||||
// string.
|
||||
!ExpectObj2Txt(nullptr, 0, false /* return name */, "") ||
|
||||
!ExpectObj2Txt(nullptr, 0, true /* don't return name */, "")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASN1_OBJECT obj;
|
||||
memset(&obj, 0, sizeof(obj));
|
||||
|
||||
if (OBJ_obj2txt(NULL, 0, &obj, 0) != -1) {
|
||||
fprintf(stderr, "OBJ_obj2txt accepted the empty OID.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// kNonMinimalOID is kBasicConstraints with the final component non-minimally
|
||||
// encoded.
|
||||
static const uint8_t kNonMinimalOID[] = {
|
||||
|
Loading…
Reference in New Issue
Block a user