From 54687cb6020049b21559f6642b2fc65e21cca68e Mon Sep 17 00:00:00 2001 From: Adam Wick Date: Tue, 28 May 2019 21:58:47 -0700 Subject: [PATCH] Add some helpful documentation for the SSH library. --- .gitignore | 3 ++- src/ed25519/mod.rs | 3 +-- src/ssh/mod.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5b67858..ce8ff9e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ Cargo.lock FlameGraph *.user_stacks **/.ghc.environment.* -tests/rsa/dist* \ No newline at end of file + +test.ed25519 \ No newline at end of file diff --git a/src/ed25519/mod.rs b/src/ed25519/mod.rs index c2cb64d..1b45cc6 100644 --- a/src/ed25519/mod.rs +++ b/src/ed25519/mod.rs @@ -5,8 +5,6 @@ //! you're not sure, this is a pretty good choice. //! //! ```rust -//! extern crate sha2; -//! //! use simple_crypto::ed25519::ED25519KeyPair; //! //! // Generate a new ED25519 key @@ -39,6 +37,7 @@ use std::collections::HashMap; use super::KeyPair; /// An ED25519 key pair +#[derive(Debug,PartialEq)] pub struct ED25519KeyPair { pub public: ED25519Public, diff --git a/src/ssh/mod.rs b/src/ssh/mod.rs index 18987ab..1a9cae5 100644 --- a/src/ssh/mod.rs +++ b/src/ssh/mod.rs @@ -1,3 +1,35 @@ +//! Most of the routines you want are exported from this module as functions, +//! not as structs, macros, enums, or what have you. In particular, you +//! probably want the `decode` or `encode` functions, or one of the functions +//! that `load`s data from disk or `write`s it. Here's some example code +//! to get you started, using a generated ED25519 key for fun: +//! +//! ```rust +//! use simple_crypto::ed25519::ED25519KeyPair; +//! use simple_crypto::ssh::*; +//! +//! // Generate a new ED25519 key +//! let mut rng = rand::rngs::OsRng::new().unwrap(); +//! let kp = ED25519KeyPair::generate(&mut rng); +//! +//! // Now that we have it, we can encode it as a handy ASCII string in memory, +//! // using a totally fake email address for fun: +//! let ascii_rep = encode_ssh(&kp, "fake@email.addr").expect("Encode failure!"); +//! +//! // As usual, we should be able to decode anything we encode, and the +//! // keys should match: +//! let (kp2, addr2) = decode_ssh(&ascii_rep).expect("Decode failure!"); +//! assert_eq!(kp, kp2); +//! assert_eq!(&addr2, "fake@email.addr"); +//! +//! // If you want to write this to a file, you can just do so directly: +//! write_ssh_keyfile("test.ed25519", &kp, "fake@email.addr").expect("write error"); +//! // And then load it back: +//! let (kp3, addr3) = load_ssh_keyfile("test.ed25519").expect("load error"); +//! // And, of course, it should be the same. +//! assert_eq!(kp, kp3); +//! assert_eq!(addr2, addr3); +//! ``` mod dsa; mod ecdsa; mod ed25519;