Serde VICI

This crate is a Rust library for using the Serde serialization framework
with data in the VICI protocol format.
Dependency
To make best use of this crate, let Serde's derive macros handle structs in your
application.
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_vici = "0.1"
If you want to handle raw binary data in VICI, such as in list-certs command, consider using serde_bytes.
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_vici = "0.1"
serde_bytes = "0.11"
Using Serde VICI
For example, serializing/deserializing the Encoding Example looks like the
following:
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, PartialEq, Serialize)]
struct RootSection {
key1: String,
section1: MainSection,
}
#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
struct MainSection {
sub_section: SubSection,
list1: Vec<String>,
}
#[derive(Debug, Deserialize, PartialEq, Serialize)]
struct SubSection {
key2: String,
}
fn main() -> Result<(), serde_vici::Error> {
let data = RootSection {
key1: "value1".to_string(),
section1: MainSection {
sub_section: SubSection {
key2: "value2".to_string(),
},
list1: vec!["item1".to_string(), "item2".to_string()],
},
};
let msg = serde_vici::to_vec(&data)?;
assert_eq!(
msg,
vec![
3, 4, b'k', b'e', b'y', b'1', 0, 6, b'v', b'a', b'l', b'u', b'e', b'1',
1, 8, b's', b'e', b'c', b't', b'i', b'o', b'n', b'1',
1, 11, b's', b'u', b'b', b'-', b's', b'e', b'c', b't', b'i', b'o', b'n',
3, 4, b'k', b'e', b'y', b'2', 0, 6, b'v', b'a', b'l', b'u', b'e', b'2',
2,
4, 5, b'l', b'i', b's', b't', b'1',
5, 0, 5, b'i', b't', b'e', b'm', b'1',
5, 0, 5, b'i', b't', b'e', b'm', b'2',
6,
2,
]
);
let deserialized_data: RootSection = serde_vici::from_slice(&msg)?;
assert_eq!(data, deserialized_data);
Ok(())
}
Using Serde VICI With Raw Bytes
For example, deserializing raw bytes into Vec<u8>, which otherwise will be treated as sequence.
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct CertResponse {
r#type: String,
flag: String,
has_privkey: bool,
#[serde(with = "serde_bytes")]
data: Vec<u8>,
subject: String,
not_before: String,
not_after: String,
}