Skip to main content

git_simple_encrypt/
lib.rs

1#![warn(clippy::nursery, clippy::cargo, clippy::pedantic)]
2#![allow(clippy::missing_errors_doc)]
3#![allow(clippy::multiple_crate_versions)]
4
5mod cli;
6mod config;
7pub mod crypt;
8mod repo;
9mod salt_cache;
10mod utils;
11
12use anyhow::Result;
13use assert2::assert;
14use crypt::{decrypt_repo, encrypt_repo};
15use repo::Repo;
16
17pub use crate::{
18    cli::{Cli, SetField, SubCommand},
19    crypt::FileHeader,
20};
21
22#[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)]
23pub fn run(cli: Cli) -> Result<()> {
24    assert!(cli.repo.is_absolute(), "repo path must be absolute");
25    let repo = Repo::open(&cli.repo)?;
26    let repo = Box::leak(Box::new(repo));
27    match cli.command {
28        SubCommand::Encrypt { paths } => encrypt_repo(repo, &paths)?,
29        SubCommand::Decrypt { paths } => decrypt_repo(repo, &paths)?,
30        SubCommand::Add { paths } => repo.conf.add_paths_to_crypt_list(&paths)?,
31        SubCommand::Set { field } => field.set(repo)?,
32        SubCommand::Pwd => repo.set_key_interactive()?,
33        SubCommand::Check { paths } => repo.check(&paths)?,
34        SubCommand::Install => repo.install_hook()?,
35    }
36    anyhow::Ok::<()>(())
37}