zlicenser-protocol 0.3.0

Shared protocol types, wire formats, cryptographic primitives, and hardware fingerprinting for the zlicenser licensing framework.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use serde::{de::DeserializeOwned, Serialize};

use crate::error::Error;

pub fn encode<T: Serialize>(value: &T) -> Result<Vec<u8>, Error> {
    let mut buf = Vec::new();
    ciborium::ser::into_writer(value, &mut buf).map_err(|e| Error::Encode(e.to_string()))?;
    Ok(buf)
}

pub fn decode<T: DeserializeOwned>(bytes: &[u8]) -> Result<T, Error> {
    ciborium::de::from_reader(bytes).map_err(|e| Error::Decode(e.to_string()))
}