Skip to content

Commit

Permalink
Extend the study case with how to deserialize with borsh
Browse files Browse the repository at this point in the history
Fix issue #21
  • Loading branch information
fadeevab committed Oct 17, 2023
1 parent 609be0e commit 604914e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ fn main() -> Result<(), Error> {
// Dump the serialized database into a file as an encrypted container.
let container = cocoon.dump(encoded, &mut file)?;

// Let's look at how to decrypt the container and parse it back.
let mut file = File::open("target/test.db").unwrap();
let encoded = cocoon.parse(&mut file).unwrap();
let decoded = Database::try_from_slice(&encoded).unwrap();

Ok(())
}
```
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@
//! In the end, you use [`Cocoon`] to put the final image into an encrypted container.
//!
//! ```
//! use borsh::BorshSerialize;
//! use borsh::{BorshDeserialize, BorshSerialize};
//! use cocoon::{Cocoon, Error};
//!
//! use std::collections::HashMap;
//! use std::fs::File;
//!
//! // Your data can be represented in any way.
//! #[derive(BorshSerialize)]
//! #[derive(BorshDeserialize, BorshSerialize)]
//! struct Database {
//! inner: HashMap<String, String>,
//! }
Expand All @@ -154,6 +154,11 @@
//! // Dump the serialized database into a file as an encrypted container.
//! let container = cocoon.dump(encoded, &mut file)?;
//!
//! // Let's look at how to decrypt the container and parse it back.
//! let mut file = File::open("target/test.db").unwrap();
//! let encoded = cocoon.parse(&mut file).unwrap();
//! let decoded = Database::try_from_slice(&encoded).unwrap();
//!
//! Ok(())
//! }
//! ```
Expand Down

0 comments on commit 604914e

Please sign in to comment.