crypto-seal 0.4.0

A small utility designed to securely "package" or seal serde-compatible data type that can passed around in an uncompromised manner.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::error::Error;
use crate::format::Format;
use alloc::vec::Vec;
use serde::Serialize;
use serde::de::DeserializeOwned;

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct Json;

impl Format for Json {
    fn serialize<T: Serialize + ?Sized>(value: &T) -> crate::Result<Vec<u8>> {
        serde_json::to_vec(value).map_err(Error::from)
    }

    fn deserialize<T: DeserializeOwned>(bytes: &[u8]) -> crate::Result<T> {
        serde_json::from_slice(bytes).map_err(Error::from)
    }
}