Crates.io | serde-crypt |
lib.rs | serde-crypt |
version | 0.1.4 |
source | src |
created_at | 2023-03-30 19:46:34.494527 |
updated_at | 2023-05-01 14:48:12.476706 |
description | The end-to-end encrypted serde::Serializer and serde::Deserializer - wasm-ready |
homepage | |
repository | https://github.com/D3PSI/serde-crypt |
max_upload_size | |
id | 825372 |
size | 14,286 |
The end-to-end encrypted serde::Serializer
and serde::Deserializer
.
wasm-ready.
use ring::rand::{SecureRandom, SystemRandom};
use serde::{Deserialize, Serialize};
use serde_crypt::setup;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
struct Example {
#[serde(with = "serde_crypt")]
private: String,
public: String,
}
fn main() -> Result<(), serde_json::Error> {
let mut key: [u8; 256] = [0; 256];
let rand_gen = SystemRandom::new();
rand_gen.fill(&mut key).unwrap();
setup(key);
let data = Example {
private: "private data".to_string(),
public: "public data".to_string(),
};
let serialized = serde_json::to_string(&data)?;
let deserialized: Example = serde_json::from_str(&serialized)?;
assert_eq!(deserialized, data);
Ok(())
}