From adfa8e1265f6155d1a582baa9929af198bb5d4de Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 1 May 2026 17:45:39 +0200 Subject: Misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- librecrypt_find_first_algorithm_.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'librecrypt_find_first_algorithm_.c') diff --git a/librecrypt_find_first_algorithm_.c b/librecrypt_find_first_algorithm_.c index 406f5ac..68cc533 100644 --- a/librecrypt_find_first_algorithm_.c +++ b/librecrypt_find_first_algorithm_.c @@ -11,9 +11,15 @@ librecrypt_find_first_algorithm_(const char *settings, size_t len) size_t i; for (i = 0u;; i++) { + /* Get next algorithm in the list */ algo = &librecrypt_algorithms_[i]; if (IS_END_OF_ALGORITHMS(algo)) break; + + /* Get match-priority, bigger is more prioritised, + * 0 is non-match, so we save if we get a bigger + * value then our current best (we start at 0 + * (no match found)) */ r = (*algo->is_algorithm)(settings, len); if (r > priority) { priority = r; @@ -21,6 +27,12 @@ librecrypt_find_first_algorithm_(const char *settings, size_t len) } } + /* NULL if all `is_algorithm` returned 0 (including if the + * last was completly empty), otherwise the first one + * (actually an arbitrary one) that returned the greated + * match-priority (which doesn't necessarily mean it's better, + * which is why we don't just break at the first match + * (`librecrypt_algorithms_` is ordered by how good they are)) */ return found; } -- cgit v1.2.3-70-g09d2