aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_find_first_algorithm_.c
diff options
context:
space:
mode:
Diffstat (limited to 'librecrypt_find_first_algorithm_.c')
-rw-r--r--librecrypt_find_first_algorithm_.c12
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;
}