int main(int argc, char** argv) {
int err;
+ // Open public key
+ FILE* public_key = fopen(ABS_SRCDIR "/examples/public-key.pem", "r");
+ if (!public_key) {
+ fprintf(stderr, "Could not open public key file: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ // Open private key
+ FILE* private_key = fopen(ABS_SRCDIR "/examples/private-key.pem", "r");
+ if (!private_key) {
+ fprintf(stderr, "Could not open private key file: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
struct loc_ctx* ctx;
err = loc_new(&ctx);
if (err < 0)
// Create a database
struct loc_writer* writer;
- err = loc_writer_new(ctx, &writer);
+ err = loc_writer_new(ctx, &writer, private_key);
if (err < 0)
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
- FILE* f = fopen("test.db", "w");
+ FILE* f = fopen("test.db", "w+");
if (!f) {
fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
+ // Verify the database signature
+ err = loc_database_verify(db, public_key);
+ if (err) {
+ fprintf(stderr, "Could not verify the database: %d\n", err);
+ exit(EXIT_FAILURE);
+ }
+
+ // Try reading something from the database
vendor = loc_database_get_vendor(db);
if (!vendor) {
fprintf(stderr, "Could not retrieve vendor\n");
loc_unref(ctx);
+ fclose(private_key);
+ fclose(public_key);
+
return EXIT_SUCCESS;
}