Fix up some integer types in crypto/asn1
tag and utype are always accessed as int, so make the structs match.
Boolean ASN1_ITEMs put an ASN1_BOOLEAN in it->size, so add a cast. Also
fix the time set_string functions to call the underlying CBS parser
directly, so they don't need to put a strlen into an int.
Bug: 516
Change-Id: Ie10e7eaf58ec0b0dec59813a0ddcb0197fce1fd1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55449
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c
index 201c654..bf09c90 100644
--- a/crypto/asn1/a_utctm.c
+++ b/crypto/asn1/a_utctm.c
@@ -82,22 +82,16 @@
}
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) {
- ASN1_UTCTIME t;
-
- t.type = V_ASN1_UTCTIME;
- t.length = strlen(str);
- t.data = (unsigned char *)str;
- if (ASN1_UTCTIME_check(&t)) {
- if (s != NULL) {
- if (!ASN1_STRING_set((ASN1_STRING *)s, (unsigned char *)str, t.length)) {
- return 0;
- }
- s->type = V_ASN1_UTCTIME;
- }
- return 1;
- } else {
+ size_t len = strlen(str);
+ CBS cbs;
+ CBS_init(&cbs, (const uint8_t *)str, len);
+ if (!CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
+ /*allow_timezone_offset=*/1) ||
+ !ASN1_STRING_set(s, str, len)) {
return 0;
}
+ s->type = V_ASN1_UTCTIME;
+ return 1;
}
ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) {