-/* $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").
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.
*
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.
*/