#serde #serialization #encryption #crypto #serializer-deserializer

serde-crypt

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

5 releases

0.1.4 May 1, 2023
0.1.3 Apr 30, 2023
0.1.2 Mar 31, 2023
0.1.1 Mar 31, 2023
0.1.0 Mar 30, 2023

#1529 in Cryptography

Download history 27/week @ 2024-03-08 7/week @ 2024-03-15 8/week @ 2024-03-29 1/week @ 2024-04-05

111 downloads per month
Used in serde-crypt-macro

GPL-3.0-or-later

12KB
162 lines

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

Dependencies

~16MB
~387K SLoC