mod admin;
pub(crate) mod header;
mod header_change;
mod journal;
mod key_file;
mod open;
mod rewrite;
pub use admin::{
Leftovers, StoreState, change_words, fresh_start, inspect, join, leftovers, plain_store,
remove_leftovers, remove_plain_if_empty, set_up,
};
pub use header::{StoreHeader, create_header, read_header, replace_header, write_stop_file};
pub use header_change::restore_header;
pub use journal::{
HeaderChange, HeaderChangeKind, Journal, RECOVERY_STALE_SECS, RecoveryMarker, read_journal,
recovery_in_progress, release_recovery,
};
pub use key_file::{
GitCheck, KeyFileError, SystemGit, check_key_location, load_key_file, save_key_file,
};
pub use open::{open_store, open_with_key};
pub use rewrite::{RewriteKind, RewritePlan, finish, migrate, read_plan, rotate, undo};
use crate::crypto::CryptoError;
pub const ENCRYPTION_DIR: &str = "encryption";
pub const HEADER_FILE: &str = "header.json";
pub const STOP_FILE: &str = "items";
pub const STOP_TEXT: &str = "This store is encrypted. Upgrade to passalong 0.2.0 or later.\n";
pub const REWRITE_DIR: &str = ".rewrite";
pub const PLAIN_DIR: &str = "plain";
pub(crate) const SEALED_TMP_DIR: &str = "v2/tmp";
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum EncryptionError {
#[error(
"item {id} is not complete yet; if the store is in a synced folder, it may still be syncing"
)]
Incomplete {
id: String,
},
#[error(transparent)]
Crypto(#[from] CryptoError),
#[error(transparent)]
KeyFile(#[from] KeyFileError),
#[error(
"the store is encrypted and this device has no key for it; run `passalong encrypt --join`"
)]
NoKey,
#[error(
"this device's key {device} is not the store's key {store}; run `passalong encrypt --join` with the store's current words"
)]
KeyMismatch {
device: String,
store: String,
},
#[error(
"this device has an encryption key, but the store is not encrypted; run `passalong encrypt` to encrypt it, or delete the key file (client.key_file)"
)]
KeyWithoutEncryption,
#[error("the store is not encrypted; run `passalong encrypt` to encrypt it")]
NotEncrypted,
#[error(
"the store's items are being re-encrypted{}; wait for that to finish, or run `passalong encrypt --recover`",
since(.started)
)]
Rewriting {
started: Option<String>,
},
#[error(
"another `passalong encrypt --recover` is running{}; wait for it to finish, or, if it was interrupted, run `passalong encrypt --recover` again to take it over",
since(.started)
)]
Recovering {
started: Option<String>,
},
#[error("the store's encryption header is missing; run `passalong encrypt --recover`")]
HeaderMissing,
#[error(
"the store's key changed while this command ran; run `passalong encrypt --join` with the new words"
)]
KeyChanged,
#[error("the store is already encrypted")]
AlreadyEncrypted,
#[error("the store header is not valid: {0}")]
Header(String),
#[error("the store's layout is unexpected: {0}")]
Layout(String),
}
fn since(started: &Option<String>) -> String {
started
.as_ref()
.map(|at| format!(" (since {at})"))
.unwrap_or_default()
}