Skip to content

custom serializer and deserializer for end-to-end encrypted serde serialization and deserialization - wasm-ready

Notifications You must be signed in to change notification settings

cedricschwyter/serde-crypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serde-crypt

Build Status Crate Docs Crate Version Crate Coverage

The end-to-end encrypted serde::Serializer and serde::Deserializer. wasm-ready.

Example

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(())
}

About

custom serializer and deserializer for end-to-end encrypted serde serialization and deserialization - wasm-ready

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages