Commit Diff


commit - 21268f10931a6c0ffd0b919e093a43dc31d86bb8
commit + 4fa88f57fead5f472c4bbd60c65d70d884ccd6ee
blob - b5b0ce30c0a1bac67fb51bddc552379a702f0577
blob + cc0587c360ac02f7f6a42d8e81b63c0454deef7f
--- fs.c
+++ fs.c
@@ -256,18 +256,6 @@ done:
 		fclose(fp);
 	else
 		load_page_from_str(tab, fallback);
-}
-
-int
-save_cert(const struct tofu_entry *e)
-{
-	FILE *f;
-
-	if ((f = fopen(known_hosts_file, "a")) == NULL)
-		return -1;
-	fprintf(f, "%s %s %d\n", e->domain, e->hash, e->verified);
-	fclose(f);
-	return 0;
 }
 
 int
blob - f6f86704ada4997fc0ab7c8d46f761999084b522
blob + 3a0e32d0833523ec7274c83695b5a8e6ce62fc12
--- include/fs.h
+++ include/fs.h
@@ -36,7 +36,6 @@ extern char	history_file[PATH_MAX], history_file_tmp[P
 int		 fs_init(void);
 int		 lock_session(void);
 void		 fs_load_url(struct tab *, const char *);
-int		 save_cert(const struct tofu_entry *e);
 int		 update_cert(const struct tofu_entry *e);
 int		 fs_load_state(struct ohash *);
 
blob - 8ffa54d566c4c5be813eae3d2923e91f125cb265
blob + f82e56c6e69ce17b86e314d41b6348f7f3c99087
--- include/telescope.h
+++ include/telescope.h
@@ -360,6 +360,7 @@ int		 ui_send_net(int, uint32_t, const void *, uint16_
 void			 tofu_init(struct ohash*, unsigned int, ptrdiff_t);
 struct tofu_entry	*tofu_lookup(struct ohash*, const char*, const char*);
 void			 tofu_add(struct ohash*, struct tofu_entry*);
+int			 tofu_save(struct ohash *, struct tofu_entry *);
 void			 tofu_update(struct ohash*, struct tofu_entry*);
 void			 tofu_temp_trust(struct ohash *, const char *, const char *, const char *);
 
blob - ff04a90ef09dc65f836eee6b836b1f6ecdde4cd5
blob + dee6570ff7ac7ca45ce207b94035af0e8fefdafb
--- telescope.c
+++ telescope.c
@@ -235,8 +235,7 @@ handle_imsg_check_cert(struct imsg *imsg, size_t datal
 			strlcat(e->domain, port, sizeof(e->domain));
 		}
 		strlcpy(e->hash, hash, sizeof(e->hash));
-		tofu_add(&certs, e);
-		save_cert(e);
+		tofu_save(&certs, e);
 	} else
 		tofu_res = !strcmp(hash, e->hash);
 
blob - b0c0dde4690cef62bd798b450774dbc010f82a50
blob + 98169515f37cd0899f98bbc088b04a23056051d8
--- tofu.c
+++ tofu.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+ * Copyright (c) 2021, 2022 Omar Polo <op@omarpolo.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -16,9 +16,11 @@
 
 #include "compat.h"
 
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "fs.h"
 #include "telescope.h"
 #include "utils.h"
 
@@ -60,6 +62,20 @@ tofu_add(struct ohash *h, struct tofu_entry *e)
 	ohash_insert(h, slot, e);
 }
 
+int
+tofu_save(struct ohash *h, struct tofu_entry *e)
+{
+	FILE *fp;
+
+	tofu_add(h, e);
+
+	if ((fp = fopen(known_hosts_file, "a")) == NULL)
+		return -1;
+	fprintf(fp, "%s %s %d\n", e->domain, e->hash, e->verified);
+	fclose(fp);
+	return 0;
+}
+
 void
 tofu_update(struct ohash *h, struct tofu_entry *e)
 {