use serde_derive::Deserialize;
use serde_derive::Serialize;
#[derive(Deserialize, Serialize, PartialEq, Debug)]
#[serde(rename = "0x420042")]
pub(crate) enum KeyFormatType {
#[serde(rename = "0x00000001")]
Raw,
#[serde(rename = "0x00000002")]
Opaque,
#[serde(rename = "0x00000007")]
TransparentSymmetricKey,
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
#[serde(rename = "0x420043")]
pub(crate) enum KeyMaterial {
#[serde(rename(deserialize = "if 0x420042 in [0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000006]"))] #[serde(rename(serialize = "Transparent"))]
Bytes(i32),
#[serde(rename(deserialize = "if 0x420042 == 0x00000007"))]
#[serde(rename(serialize = "Transparent"))]
TransparentSymmetricKey(String),
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
#[serde(rename = "0x123456")]
pub(crate) struct SomeKey {
pub key_format_type: KeyFormatType, pub key_material: KeyMaterial, }
pub(crate) mod some_transparent_key {
pub fn ttlv_bytes() -> Vec<u8> {
let test_data = concat!(
"123456 01 00000020",
" 420042 05 00000004 00000007 00000000", " 420043 07 00000004 426C6168 00000000" );
hex::decode(test_data.replace(" ", "")).unwrap()
}
}
pub(crate) mod some_raw_key {
pub fn ttlv_bytes() -> Vec<u8> {
let test_data = concat!(
"123456 01 00000020",
" 420042 05 00000004 00000001 00000000", " 420043 02 00000004 000000FF 00000000" );
hex::decode(test_data.replace(" ", "")).unwrap()
}
}
pub(crate) mod some_opaque_key {
pub fn ttlv_bytes() -> Vec<u8> {
let test_data = concat!(
"123456 01 00000020",
" 420042 05 00000004 00000002 00000000", " 420043 02 00000004 000000F0 00000000" );
hex::decode(test_data.replace(" ", "")).unwrap()
}
}
pub(crate) mod some_unknown_key_type {
pub fn ttlv_bytes() -> Vec<u8> {
let test_data = concat!(
"123456 01 00000020",
" 420042 05 00000004 00000099 00000000", " 420043 02 00000004 000000F0 00000000" );
hex::decode(test_data.replace(" ", "")).unwrap()
}
}