diff options
| author | Mattias Andrée <m@maandree.se> | 2026-05-01 17:45:39 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-05-01 17:45:39 +0200 |
| commit | adfa8e1265f6155d1a582baa9929af198bb5d4de (patch) | |
| tree | e3cee62aa5a8768621cd294295f787b8cc54141b /librecrypt_find_first_algorithm_.c | |
| parent | Add librecrypt.7 and README (diff) | |
| download | librecrypt-adfa8e1265f6155d1a582baa9929af198bb5d4de.tar.gz librecrypt-adfa8e1265f6155d1a582baa9929af198bb5d4de.tar.bz2 librecrypt-adfa8e1265f6155d1a582baa9929af198bb5d4de.tar.xz | |
Misc
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | librecrypt_find_first_algorithm_.c | 12 |
1 files changed, 12 insertions, 0 deletions
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; } |
