diff options
author | tb <> | 2022-01-04 20:30:30 +0000 |
---|---|---|
committer | tb <> | 2022-01-04 20:30:30 +0000 |
commit | 191a8ff01f214920fa1d8dd7be9fa3513400f74a (patch) | |
tree | b9c90c6d23705d027bdb5a6928e006d09b58cab2 /src | |
parent | 54d9eac5c87b49e6b2fa7b089f4fc8722c8d69cf (diff) | |
download | openbsd-191a8ff01f214920fa1d8dd7be9fa3513400f74a.tar.gz openbsd-191a8ff01f214920fa1d8dd7be9fa3513400f74a.tar.bz2 openbsd-191a8ff01f214920fa1d8dd7be9fa3513400f74a.zip |
Refactor extract_min_max()
extract_min_max() crammed all the work in two return statements
inside a switch. Make this more readable by splitting out the
extraction of the min and max as BIT STRINGs from an addressPrefix
or an addressRange and once that's done expanding them to raw
addresses.
ok inoguchi jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/x509/x509_addr.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/lib/libcrypto/x509/x509_addr.c b/src/lib/libcrypto/x509/x509_addr.c index d3cdebba25..e80ba35661 100644 --- a/src/lib/libcrypto/x509/x509_addr.c +++ b/src/lib/libcrypto/x509/x509_addr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_addr.c,v 1.54 2022/01/04 20:23:05 tb Exp $ */ | 1 | /* $OpenBSD: x509_addr.c,v 1.55 2022/01/04 20:30:30 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Contributed to the OpenSSL Project by the American Registry for | 3 | * Contributed to the OpenSSL Project by the American Registry for |
4 | * Internet Numbers ("ARIN"). | 4 | * Internet Numbers ("ARIN"). |
@@ -1060,6 +1060,23 @@ X509v3_addr_add_range(IPAddrBlocks *addr, const unsigned afi, | |||
1060 | return 1; | 1060 | return 1; |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | static int | ||
1064 | extract_min_max_bitstr(IPAddressOrRange *aor, ASN1_BIT_STRING **out_min, | ||
1065 | ASN1_BIT_STRING **out_max) | ||
1066 | { | ||
1067 | switch (aor->type) { | ||
1068 | case IPAddressOrRange_addressPrefix: | ||
1069 | *out_min = *out_max = aor->u.addressPrefix; | ||
1070 | return 1; | ||
1071 | case IPAddressOrRange_addressRange: | ||
1072 | *out_min = aor->u.addressRange->min; | ||
1073 | *out_max = aor->u.addressRange->max; | ||
1074 | return 1; | ||
1075 | default: | ||
1076 | return 0; | ||
1077 | } | ||
1078 | } | ||
1079 | |||
1063 | /* | 1080 | /* |
1064 | * Extract min and max values from an IPAddressOrRange. | 1081 | * Extract min and max values from an IPAddressOrRange. |
1065 | */ | 1082 | */ |
@@ -1067,18 +1084,18 @@ static int | |||
1067 | extract_min_max(IPAddressOrRange *aor, unsigned char *min, unsigned char *max, | 1084 | extract_min_max(IPAddressOrRange *aor, unsigned char *min, unsigned char *max, |
1068 | int length) | 1085 | int length) |
1069 | { | 1086 | { |
1087 | ASN1_BIT_STRING *min_bitstr, *max_bitstr; | ||
1088 | |||
1070 | if (aor == NULL || min == NULL || max == NULL) | 1089 | if (aor == NULL || min == NULL || max == NULL) |
1071 | return 0; | 1090 | return 0; |
1072 | switch (aor->type) { | 1091 | |
1073 | case IPAddressOrRange_addressPrefix: | 1092 | if (!extract_min_max_bitstr(aor, &min_bitstr, &max_bitstr)) |
1074 | return (addr_expand(min, aor->u.addressPrefix, length, 0x00) && | 1093 | return 0; |
1075 | addr_expand(max, aor->u.addressPrefix, length, 0xff)); | 1094 | |
1076 | case IPAddressOrRange_addressRange: | 1095 | if (!addr_expand(min, min_bitstr, length, 0)) |
1077 | return (addr_expand(min, aor->u.addressRange->min, length, | 1096 | return 0; |
1078 | 0x00) && | 1097 | |
1079 | addr_expand(max, aor->u.addressRange->max, length, 0xff)); | 1098 | return addr_expand(max, max_bitstr, length, 1); |
1080 | } | ||
1081 | return 0; | ||
1082 | } | 1099 | } |
1083 | 1100 | ||
1084 | /* | 1101 | /* |