diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2022-01-05 17:44:31 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2022-01-05 17:44:31 +0000 |
commit | 3a4131f5eed3ab0237168059fbc1af4a8c023e03 (patch) | |
tree | 46c4ffb77b1727178cefd4bac77b93445843b15c | |
parent | a4a13dc7c62a755c0c2331e15bd1b3a1025b64c5 (diff) |
Hoist IPAddressFamily_cmp() to the other IPAddressFamily functions.
ok inoguchi jsing
-rw-r--r-- | lib/libcrypto/x509/x509_addr.c | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/lib/libcrypto/x509/x509_addr.c b/lib/libcrypto/x509/x509_addr.c index acf1321c93b..54cfd485cdf 100644 --- a/lib/libcrypto/x509/x509_addr.c +++ b/lib/libcrypto/x509/x509_addr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_addr.c,v 1.67 2022/01/05 17:43:04 tb Exp $ */ +/* $OpenBSD: x509_addr.c,v 1.68 2022/01/05 17:44:30 tb Exp $ */ /* * Contributed to the OpenSSL Project by the American Registry for * Internet Numbers ("ARIN"). @@ -452,6 +452,34 @@ IPAddressFamily_afi_length(const IPAddressFamily *f, int *out_length) return 1; } +#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) + +/* + * Sort comparison function for a sequence of IPAddressFamily. + * + * The last paragraph of RFC 3779 2.2.3.3 is slightly ambiguous about + * the ordering: I can read it as meaning that IPv6 without a SAFI + * comes before IPv4 with a SAFI, which seems pretty weird. The + * examples in appendix B suggest that the author intended the + * null-SAFI rule to apply only within a single AFI, which is what I + * would have expected and is what the following code implements. + */ +static int +IPAddressFamily_cmp(const IPAddressFamily *const *a_, + const IPAddressFamily *const *b_) +{ + const ASN1_OCTET_STRING *a = (*a_)->addressFamily; + const ASN1_OCTET_STRING *b = (*b_)->addressFamily; + int len, cmp; + + len = MINIMUM(a->length, b->length); + + if ((cmp = memcmp(a->data, b->data, len)) != 0) + return cmp; + + return a->length - b->length; +} + /* * Extract the AFI from an IPAddressFamily. * @@ -1130,34 +1158,6 @@ X509v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, return afi_len; } -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -/* - * Sort comparison function for a sequence of IPAddressFamily. - * - * The last paragraph of RFC 3779 2.2.3.3 is slightly ambiguous about - * the ordering: I can read it as meaning that IPv6 without a SAFI - * comes before IPv4 with a SAFI, which seems pretty weird. The - * examples in appendix B suggest that the author intended the - * null-SAFI rule to apply only within a single AFI, which is what I - * would have expected and is what the following code implements. - */ -static int -IPAddressFamily_cmp(const IPAddressFamily *const *a_, - const IPAddressFamily *const *b_) -{ - const ASN1_OCTET_STRING *a = (*a_)->addressFamily; - const ASN1_OCTET_STRING *b = (*b_)->addressFamily; - int len, cmp; - - len = MINIMUM(a->length, b->length); - - if ((cmp = memcmp(a->data, b->data, len)) != 0) - return cmp; - - return a->length - b->length; -} - /* * Check whether an IPAddrBLocks is in canonical form. */ |