snapper_box/entries.rs
1//! Data types for the control structure of a [`CryptoBox`](crate::CryptoBox)
2
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8use crate::crypto::DerivedKey;
9
10/// Can contain any control structure in a [`CryptoBox`](crate::CryptoBox)
11#[derive(Clone, Serialize, Deserialize)]
12#[non_exhaustive]
13pub enum Control {
14 /// Stores the default settings for the [`CryptoBox`](crate::CryptoBox)
15 ///
16 /// This lives at the empty string (`""`) path in the root namespace
17 Settings(Settings),
18 /// List of namespaces in the [`CryptoBox`](crate::CryptoBox)
19 ///
20 /// This lives at the `"namespaces"` path in the root namespace
21 Namespaces(Namespaces),
22}
23
24/// Initial configuration settings for a [`CryptoBox`](crate::CryptoBox)
25#[derive(Debug, Hash, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
26pub struct Settings {
27 /// Compression level for this box
28 pub compression: Option<i32>,
29 /// Default maximum write cache entries for this box
30 pub max_cache_entries: Option<usize>,
31}
32
33/// The namespaces control structure
34#[derive(Clone, Serialize, Deserialize)]
35pub struct Namespaces {
36 /// The list of namespaces
37 pub namespaces: Vec<Namespace>,
38}
39
40/// Information about a Namespace
41#[derive(Hash, Clone, Serialize, Deserialize)]
42pub struct Namespace {
43 /// The name of this namespace
44 pub name: String,
45 /// The derived key for this namespace
46 pub key: Arc<DerivedKey>,
47 /// The [`Uuid`] of this namespace
48 pub uuid: Uuid,
49}