]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: add helper functions to use VeritySettings in hash/set
authorLuca Boccassi <luca.boccassi@gmail.com>
Tue, 18 Feb 2025 14:44:44 +0000 (14:44 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 18 Feb 2025 14:44:51 +0000 (14:44 +0000)
src/shared/dissect-image.c
src/shared/dissect-image.h

index 5ab0f9fe18376586caa1c5c917ecdb289d818628..724aedc532ee7d6fed79eb4ce27c329fd71a6f6d 100644 (file)
@@ -3172,6 +3172,33 @@ void verity_settings_done(VeritySettings *v) {
         v->data_path = mfree(v->data_path);
 }
 
+VeritySettings* verity_settings_free(VeritySettings *v) {
+        if (!v)
+                return NULL;
+
+        verity_settings_done(v);
+        return mfree(v);
+}
+
+void verity_settings_hash_func(const VeritySettings *s, struct siphash *state) {
+        assert(s);
+
+        siphash24_compress_typesafe(s->root_hash_size, state);
+        siphash24_compress(s->root_hash, s->root_hash_size, state);
+}
+
+int verity_settings_compare_func(const VeritySettings *x, const VeritySettings *y) {
+        int r;
+
+        r = CMP(x->root_hash_size, y->root_hash_size);
+        if (r != 0)
+                return r;
+
+        return memcmp(x->root_hash, y->root_hash, x->root_hash_size);
+}
+
+DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(verity_settings_hash_ops, VeritySettings, verity_settings_hash_func, verity_settings_compare_func, VeritySettings, verity_settings_free);
+
 int verity_settings_load(
                 VeritySettings *verity,
                 const char *image,
index c001915e8947705eca460392d377d35e8c7b3765..9de93039da6b3bd61b40c11115d1941fbf23ff54 100644 (file)
@@ -211,6 +211,12 @@ static inline bool verity_settings_set(const VeritySettings *settings) {
 }
 
 void verity_settings_done(VeritySettings *verity);
+VeritySettings* verity_settings_free(VeritySettings *v);
+void verity_settings_hash_func(const VeritySettings *s, struct siphash *state);
+int verity_settings_compare_func(const VeritySettings *x, const VeritySettings *y);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(VeritySettings*, verity_settings_free);
+extern const struct hash_ops verity_settings_hash_ops;
 
 static inline bool verity_settings_data_covers(const VeritySettings *verity, PartitionDesignator d) {
         /* Returns true if the verity settings contain sufficient information to cover the specified partition */