coven/coven_device_secrets.rs
1//! This device's own secrets, which belong to no store (E11).
2
3use super::Coven;
4use coven_crypto::custody::KeyError;
5
6impl Coven {
7 /// This device's secret `name`, or `None` if it was never set (E11). A
8 /// device secret belongs to the device, not to a store: every store on
9 /// this device reads the same one, and deleting a store leaves it. Under
10 /// `Coven::in_memory` it lives in the test's in-memory keychain.
11 pub fn device_secret(&self, name: &str) -> Result<Option<String>, KeyError> {
12 self.keychain.device_secret(name)
13 }
14
15 /// Keep `value` as this device's secret `name`, such as a pairing with a
16 /// speaker, in a device-only entry under the app's keychain service and
17 /// the same access policy as coven's keys (E11). Names are arbitrary
18 /// strings. Coven records the name in this device's secret list before
19 /// writing the value, so `delete_device_secrets` finds every saved
20 /// secret; a failure between the two may leave an extra name, and
21 /// retrying is safe.
22 pub fn set_device_secret(&self, name: &str, value: &str) -> Result<(), KeyError> {
23 self.keychain.set_device_secret(name, value)
24 }
25
26 /// Delete every device secret, then their list, without the app naming
27 /// them or coven decoding a value, as an app's reset of this device does
28 /// (E11). Store entries and the person's entries stay. Absent entries
29 /// succeed, so retrying after a failure finishes.
30 pub fn delete_device_secrets(&self) -> Result<(), KeyError> {
31 self.keychain.delete_device_secrets()
32 }
33}
34
35#[cfg(test)]
36#[path = "coven_device_secrets_tests.rs"]
37mod tests;