chunk: Add utility that compares the prefix of two chunks
Unlike chunk_compare() this first compares the prefix of two nonces, then falls back to comparing the length. This is basically intended to compare nonces as specified in RFC 7296: "Lowest" means an octet-by-octet comparison (instead of, for instance, comparing the nonces as large integers). In other words, start by comparing the first octet; if they're equal, move to the next octet, and so on. If you reach the end of one nonce, that nonce is the lower one.
This commit is contained in:
@@ -331,11 +331,26 @@ static inline chunk_t chunk_skip_zero(chunk_t chunk)
|
||||
chunk_t chunk_copy_pad(chunk_t dst, chunk_t src, u_char chr);
|
||||
|
||||
/**
|
||||
* Compare two chunks, returns zero if a equals b
|
||||
* or negative/positive if a is small/greater than b
|
||||
* Compare two chunks, returns zero if they are equal or negative/positive if
|
||||
* a is smaller/greater than b.
|
||||
*
|
||||
* Note that if the chunks are not of equal length, their prefix is not
|
||||
* compared, only their lengths.
|
||||
*/
|
||||
int chunk_compare(chunk_t a, chunk_t b);
|
||||
|
||||
/**
|
||||
* Compare two chunks, returns zero if they are equal or negative/positive if
|
||||
* a is smaller/greater than b.
|
||||
*
|
||||
* Unlike chunk_compare(), this first compares the two chunks' prefix and only
|
||||
* then falls back to comparing their lengths (shorter is "lower") if the
|
||||
* prefix is equal.
|
||||
*
|
||||
* This can e.g. be used to compare nonces.
|
||||
*/
|
||||
int chunk_compare_prefix(chunk_t a, chunk_t b);
|
||||
|
||||
/**
|
||||
* Compare two chunks for equality,
|
||||
* NULL chunks are never equal.
|
||||
|
||||
Reference in New Issue
Block a user