Skip to content

Commit

Permalink
Add code example from crate docs to readme, use readme in crate docs
Browse files Browse the repository at this point in the history
In order to simplify documentation, this commit moves most of the
documentation directly into the README.md. Additionally, to avoid
duplication, this commit pulls in the README.md into the crate docs.
This allows one source of truth for documentation and a common
experience between viewing the crate on github, crates.io, and docs.rs.
  • Loading branch information
endoze committed Nov 9, 2024
1 parent facb876 commit 04d787d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,32 @@ layer.

Documentation is available on [Docs.rs](https://docs.rs/message_verifier).

### Examples

### A Small Example

```
extern crate message_verifier;
use message_verifier::{Verifier, Encryptor, AesHmacEncryptor, DerivedKeyParams};
fn main() {
let key_base = "helloworld";
let salt = "test salt";
let sign_salt = "test signed salt";
let verifier = Verifier::new(key_base);
//let dkp = DerivedKeyParams::default();
//let encryptor = AesHmacEncryptor::new(key_base, salt, sign_salt, dkp).unwrap();
let message = "{\"key\":\"value\"}";
println!("{}", verifier.generate(message).expect("Verifier failed"));
//println!("{}", encryptor.encrypt_and_sign(message).expect("Encryptor failed"));
}
```

### More Examples

The examples directory contains two Rust examples as well as two small
Ruby scripts to demonstrate interoperability between this library and
Expand Down Expand Up @@ -72,3 +97,4 @@ If you need more cipher options, please open an issue or submit a PR!

- [mjc-gh](https://github.com/mjc-gh/)
- [seanlinsley](https://github.com/seanlinsley)
- [endoze](https://github.com/endoze)
31 changes: 1 addition & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
//! Message Verifier library compatible with Rails'
//! [MessageVerifier](http://api.rubyonrails.org/classes/ActiveSupport/MessageVerifier.html) and
//! [MessageEncryptor](http://api.rubyonrails.org/classes/ActiveSupport/MessageEncryptor.html).
//!
//! #### A Small Example
//!
//! Please refer to the
//! [README](https://github.com/mikeycgto/message_verifier/blob/master/README.md)
//! and [repo](https://github.com/mikeycgto/message_verifier) for more examples.
//!
//! ```
//! extern crate message_verifier;
//!
//! use message_verifier::{Verifier, Encryptor, AesHmacEncryptor, DerivedKeyParams};
//!
//! fn main() {
//! let key_base = "helloworld";
//! let salt = "test salt";
//! let sign_salt = "test signed salt";
//!
//! let verifier = Verifier::new(key_base);
//!
//! //let dkp = DerivedKeyParams::default();
//! //let encryptor = AesHmacEncryptor::new(key_base, salt, sign_salt, dkp).unwrap();
//!
//! let message = "{\"key\":\"value\"}";
//!
//! println!("{}", verifier.generate(message).expect("Verifier failed"));
//! //println!("{}", encryptor.encrypt_and_sign(message).expect("Encryptor failed"));
//! }
//! ```
#![doc = include_str!("../README.md")]

#[macro_use]
extern crate error_chain;
Expand Down

0 comments on commit 04d787d

Please sign in to comment.