aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_find_first_algorithm_.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-04-26 22:36:47 +0200
committerMattias Andrée <m@maandree.se>2026-04-26 22:36:47 +0200
commitd77ab463184d113ca6119403887c9f4ed0dfdf0b (patch)
treeca8a1de443f90a4b7def56ea5b61c96aaa949f45 /librecrypt_find_first_algorithm_.c
downloadlibrecrypt-d77ab463184d113ca6119403887c9f4ed0dfdf0b.tar.gz
librecrypt-d77ab463184d113ca6119403887c9f4ed0dfdf0b.tar.bz2
librecrypt-d77ab463184d113ca6119403887c9f4ed0dfdf0b.tar.xz
First commit
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'librecrypt_find_first_algorithm_.c')
-rw-r--r--librecrypt_find_first_algorithm_.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/librecrypt_find_first_algorithm_.c b/librecrypt_find_first_algorithm_.c
new file mode 100644
index 0000000..406f5ac
--- /dev/null
+++ b/librecrypt_find_first_algorithm_.c
@@ -0,0 +1,41 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+
+const struct algorithm *
+librecrypt_find_first_algorithm_(const char *settings, size_t len)
+{
+ unsigned r, priority = 0;
+ const struct algorithm *algo, *found = NULL;
+ size_t i;
+
+ for (i = 0u;; i++) {
+ algo = &librecrypt_algorithms_[i];
+ if (IS_END_OF_ALGORITHMS(algo))
+ break;
+ r = (*algo->is_algorithm)(settings, len);
+ if (r > priority) {
+ priority = r;
+ found = algo;
+ }
+ }
+
+ return found;
+}
+
+
+#else
+
+
+int
+main(void)
+{
+ SET_UP_ALARM();
+
+ return 0;
+}
+
+
+#endif
+/* TODO test */