1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//! *Library for encrypting and decryping age messages* //! //! age is a simple, secure, and modern encryption tool with small explicit keys, no //! config options, and UNIX-style composability. //! //! All crate versions prior to 1.0 are **beta releases** for testing purposes. The age //! specification is available [here](https://age-encryption.org/v1). //! //! # Examples //! //! ## Key-based encryption //! //! ``` //! use std::io::{Read, Write}; //! //! # fn run_main() -> Result<(), age::Error> { //! let key = age::SecretKey::generate(); //! let pubkey = key.to_public(); //! //! let plaintext = b"Hello world!"; //! //! let encryptor = age::Encryptor::Keys(vec![pubkey]); //! let mut encrypted = vec![]; //! { //! let mut writer = encryptor.wrap_output(&mut encrypted, false)?; //! writer.write_all(plaintext)?; //! writer.finish()?; //! }; //! //! let decryptor = age::Decryptor::Keys(vec![key.into()]); //! let mut reader = decryptor.trial_decrypt(&encrypted[..], |_| None)?; //! let mut decrypted = vec![]; //! reader.read_to_end(&mut decrypted); //! //! assert_eq!(decrypted, plaintext); //! # Ok(()) //! # } //! # fn main() { run_main().unwrap(); } //! ``` //! //! ## Passphrase-based encryption //! //! ``` //! use secrecy::Secret; //! use std::io::{Read, Write}; //! //! # fn run_main() -> Result<(), age::Error> { //! let plaintext = b"Hello world!"; //! let passphrase = "this is not a good passphrase"; //! //! let encryptor = age::Encryptor::Passphrase(Secret::new(passphrase.to_owned())); //! let mut encrypted = vec![]; //! { //! let mut writer = encryptor.wrap_output(&mut encrypted, false)?; //! writer.write_all(plaintext)?; //! writer.finish()?; //! }; //! //! let decryptor = age::Decryptor::Passphrase(Secret::new(passphrase.to_owned())); //! let mut reader = decryptor.trial_decrypt(&encrypted[..], |_| None)?; //! let mut decrypted = vec![]; //! reader.read_to_end(&mut decrypted); //! //! assert_eq!(decrypted, plaintext); //! # Ok(()) //! # } //! # fn main() { run_main().unwrap(); } //! ``` // Catch documentation errors caused by code changes. #![deny(intra_doc_link_resolution_failure)] #![deny(missing_docs)] mod error; mod format; pub mod keys; mod openssh; mod primitives; mod protocol; mod util; pub use error::Error; pub use keys::SecretKey; pub use primitives::stream::StreamReader; pub use protocol::{Decryptor, Encryptor}; #[cfg(feature = "cli-common")] pub mod cli_common;