diff --git a/core/src/store.rs b/core/src/store.rs index 48ca556..1b09873 100644 --- a/core/src/store.rs +++ b/core/src/store.rs @@ -283,6 +283,15 @@ impl Store { .and_then(|k| k.try_into().ok())) } + /// Removes a pin: the settings screen's unpin, the inverse of + /// `pin_server`. The next session against that host is trust on first + /// use again (sec 4, sec 8). + pub fn unpin_server(&self, host: &str) -> Result<(), Error> { + self.db() + .execute("DELETE FROM servers WHERE host = ?1", params![host])?; + Ok(()) + } + /// Every pin, host and key, ordered by host — the export's server map. pub fn pins(&self) -> Result, Error> { let db = self.db(); @@ -881,6 +890,16 @@ mod tests { assert_eq!(store.history("alice@example.org").unwrap(), [([9u8; 32], 42)]); } + #[test] + fn unpin_returns_to_trust_on_first_use() { + let store = temp_store("unpin"); + store.pin_server("example.org", &[1u8; KEY_LEN]).unwrap(); + store.unpin_server("example.org").unwrap(); + assert_eq!(store.server_pin("example.org").unwrap(), None); + // Unpinning what was never pinned is not an error. + store.unpin_server("never.example.org").unwrap(); + } + #[test] fn kept_survives_the_folder_listing() { let store = temp_store("kept");