Read Secret
docs
A rust library that provides an easy way to read and decrypt secrets from your environment variables and files.
Code is hosted on sourcehut, and it is recommended to open issues/send patches on this platform. However, GitHub is also acceptable.
Usage
Run command cargo add read-secret or put the following code into your cargo.toml
[dependencies]
read-secret = <version>
Example
This example code is in file examples/e1.es, and you can run it by executing cargo run --example e1
use read_secret::{DecryptMethod, SecretType};
use std::process::Command;
fn main() {
let mut dm = DecryptMethod::None;
let st = SecretType::Env("XDG_SESSION_TYPE".to_string());
let sr = read_secret::read_secret(st, &mut dm).unwrap();
assert_eq!("wayland", sr);
let mut dm = DecryptMethod::GPG;
let st = SecretType::File("examples/pass_gpg.asc".to_string());
let sr = read_secret::read_secret(st, &mut dm).unwrap();
assert_eq!("El Psy Kongaroo", sr);
let mut temp = Command::new("wc"); let custom_command = temp.args(["-c"]);
let mut dm = DecryptMethod::Custom(custom_command);
let st = SecretType::String("El Psy Kongaroo".to_string());
let sr = read_secret::read_secret(st, &mut dm).unwrap();
assert_eq!("15\n", sr);
}