]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/test-signature.c
location: Implement listing bogons
[people/ms/libloc.git] / src / test-signature.c
index 4c778a0f771a686a457fc52f45edcdc636626096..620517c922469708976f5afe41398043c0d92758 100644 (file)
@@ -22,6 +22,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <unistd.h>
+#include <syslog.h>
 
 #include <loc/libloc.h>
 #include <loc/database.h>
@@ -38,8 +39,14 @@ int main(int argc, char** argv) {
        }
 
        // Open private key
-       FILE* private_key = fopen(ABS_SRCDIR "/examples/private-key.pem", "r");
-       if (!private_key) {
+       FILE* private_key1 = fopen(ABS_SRCDIR "/examples/private-key.pem", "r");
+       if (!private_key1) {
+               fprintf(stderr, "Could not open private key file: %s\n", strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
+       FILE* private_key2 = fopen(ABS_SRCDIR "/examples/private-key.pem", "r");
+       if (!private_key2) {
                fprintf(stderr, "Could not open private key file: %s\n", strerror(errno));
                exit(EXIT_FAILURE);
        }
@@ -49,13 +56,16 @@ int main(int argc, char** argv) {
        if (err < 0)
                exit(EXIT_FAILURE);
 
+       // Enable debug logging
+       loc_set_log_priority(ctx, LOG_DEBUG);
+
        // Create an empty database
        struct loc_writer* writer;
-       err = loc_writer_new(ctx, &writer, private_key, NULL);
+       err = loc_writer_new(ctx, &writer, private_key1, private_key2);
        if (err < 0)
                exit(EXIT_FAILURE);
 
-       FILE* f = fopen("test.db", "w+");
+       FILE* f = tmpfile();
        if (!f) {
                fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
                exit(EXIT_FAILURE);
@@ -68,16 +78,7 @@ int main(int argc, char** argv) {
        }
        loc_writer_unref(writer);
 
-       // Close the file
-       fclose(f);
-
        // And open it again from disk
-       f = fopen("test.db", "r");
-       if (!f) {
-               fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-
        struct loc_database* db;
        err = loc_database_new(ctx, &db, f);
        if (err) {
@@ -108,10 +109,11 @@ int main(int argc, char** argv) {
 
        // Close the database
        loc_database_unref(db);
-
        loc_unref(ctx);
+       fclose(f);
 
-       fclose(private_key);
+       fclose(private_key1);
+       fclose(private_key2);
        fclose(public_key);
 
        return EXIT_SUCCESS;