pub struct FileProtocolStateStorage { /* private fields */ }Expand description
Protocol-state storage in plain files, in the format the Python, Swift and Kotlin providers write.
A record lives at <root>/<namespace>/t_<sha256(type)>/k_<sha256(type, id)>
and carries its own key in a header (see the module docs), so every file is
attributable and a read verifies it opened the record it asked for. The
directory is portable: a store written by the Python binding opens here for
the same account, and the reverse.
Values are stored verbatim. The engine seals every category that can carry message plaintext or key material before it reaches this trait, so those arrive as ciphertext under the record key held in the MLS store. Record keys are peer and message ids and are not sealed; the file names are an unsalted digest of them, so anyone who can list the directory can confirm a guessed id. Directories are created owner-only for that reason.
Implementations§
Source§impl FileProtocolStateStorage
impl FileProtocolStateStorage
Sourcepub fn open(
root: impl AsRef<Path>,
namespace: &str,
) -> Result<Self, FileStoreError>
pub fn open( root: impl AsRef<Path>, namespace: &str, ) -> Result<Self, FileStoreError>
Opens (creating if needed) the store at <root>/<namespace>/.
namespace must be super::account_storage_namespace of the
application id and profile; anything else is refused before a
directory is created. root should be a directory the host removes
when the installation is removed: protocol state is scoped to an
installation, and a store that outlives it resends settled work.
A second store over the same directory is refused with
FileStoreError::InUse until this one is closed or dropped.
Examples found in repository?
44fn open_stores(
45 root: &std::path::Path,
46 key: &dyn StoreKeyProvider,
47) -> Result<(Arc<SealedFileMlsStorage>, Arc<FileProtocolStateStorage>), Box<dyn std::error::Error>>
48{
49 let namespace = account_storage_namespace(APP_ID, PROFILE);
50 // Two roots: MLS material may outlive an installation, protocol state
51 // must not.
52 let secure = SealedFileMlsStorage::open(root.join("keys"), &namespace, key)?;
53 let records = FileProtocolStateStorage::open(root.join("state"), &namespace)?;
54 Ok((Arc::new(secure), Arc::new(records)))
55}Sourcepub fn close(&self)
pub fn close(&self)
Releases the directory and refuses every later operation.
The lock goes at once, whoever still holds the store. An operation in flight finishes first. Afterwards every operation is an error naming the directory, and a new store may open over it. Closing twice is closing once.
Sourcepub fn sealed_state(
&self,
secure: &dyn MlsStorage,
) -> Result<SealedState, FileStoreError>
pub fn sealed_state( &self, secure: &dyn MlsStorage, ) -> Result<SealedState, FileStoreError>
What the record key secure holds makes of the sealed records here.
Read-only on both stores: nothing is deleted, and no record key is
generated. A record whose framing does not parse is passed over, since
it says nothing about any key. A record that cannot be read at all is
an FileStoreError::Io, and a record key the MLS store cannot read
(as opposed to one it does not hold, or holds damaged) is an
FileStoreError::RecordKeyUnreadable: neither is taken for an
answer.
Sourcepub fn holds_records(
root: impl AsRef<Path>,
namespace: &str,
) -> Result<bool, FileStoreError>
pub fn holds_records( root: impl AsRef<Path>, namespace: &str, ) -> Result<bool, FileStoreError>
Whether <root>/<namespace>/ holds protocol state, without opening,
creating or locking anything.
A record file in a type directory, which is where this store and
every binding’s provider put a record. Not the lock file an open
leaves, not a type directory every record has since been deleted
from, and not what the MLS store leaves in a directory the two were
wrongly made to share: none of those is state a new identity could
strand. A directory that cannot be read, at either level, is an
FileStoreError::Io, never “no state”.
Trait Implementations§
Source§impl Debug for FileProtocolStateStorage
impl Debug for FileProtocolStateStorage
Source§impl ProtocolStateStorage for FileProtocolStateStorage
impl ProtocolStateStorage for FileProtocolStateStorage
Source§fn store(
&self,
key_type: &str,
key_id: &str,
data: &[u8],
) -> ProtocolStateResult<()>
fn store( &self, key_type: &str, key_id: &str, data: &[u8], ) -> ProtocolStateResult<()>
Source§fn load(
&self,
key_type: &str,
key_id: &str,
) -> ProtocolStateResult<Option<Vec<u8>>>
fn load( &self, key_type: &str, key_id: &str, ) -> ProtocolStateResult<Option<Vec<u8>>>
None when absent. Read moreAuto Trait Implementations§
impl !Freeze for FileProtocolStateStorage
impl RefUnwindSafe for FileProtocolStateStorage
impl Send for FileProtocolStateStorage
impl Sync for FileProtocolStateStorage
impl Unpin for FileProtocolStateStorage
impl UnsafeUnpin for FileProtocolStateStorage
impl UnwindSafe for FileProtocolStateStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);