SecureStorage

Trait SecureStorage 

Source
pub trait SecureStorage {
    // Required methods
    fn store(&self, key: &str, value: &[u8]) -> Result<(), PersistenceError>;
    fn retrieve(&self, key: &str) -> Result<Option<Vec<u8>>, PersistenceError>;
    fn delete(&self, key: &str) -> Result<(), PersistenceError>;

    // Provided method
    fn exists(&self, key: &str) -> Result<bool, PersistenceError> { ... }
}
Expand description

Platform-agnostic secure storage abstraction.

Implementations should use platform-specific secure storage:

  • Android: EncryptedSharedPreferences / Keystore
  • iOS: Keychain Services
  • Linux: Encrypted file in XDG data directory
  • ESP32: Encrypted NVS partition
  • Windows: DPAPI

Required Methods§

Source

fn store(&self, key: &str, value: &[u8]) -> Result<(), PersistenceError>

Store bytes under the given key.

The implementation should encrypt the data at rest using platform-appropriate mechanisms.

Source

fn retrieve(&self, key: &str) -> Result<Option<Vec<u8>>, PersistenceError>

Retrieve bytes for the given key.

Returns Ok(None) if the key doesn’t exist. Returns Err if the key exists but cannot be decrypted.

Source

fn delete(&self, key: &str) -> Result<(), PersistenceError>

Delete the entry for the given key.

Returns Ok(()) even if the key didn’t exist.

Provided Methods§

Source

fn exists(&self, key: &str) -> Result<bool, PersistenceError>

Check if a key exists without retrieving its value.

Implementors§

Source§

impl SecureStorage for MemoryStorage

Available on crate features std only.