use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct ChannelAuthorize<'a> {
pub signature: Cow<'a, str>,
pub credentials: Option<Cow<'a, [Cow<'a, str>]>>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_channel_authorize_deserialize() {
let json = r#"{
"signature": "304402204EF0AFB78AC23ED1C472E74F4299C0C21F1B21D07EFC0A3838A420F76D783A400220154FB11B6F54320666E4C36CA7F686C16A3A0456800BBC43746F34AF50290064"
}"#;
let result: ChannelAuthorize = serde_json::from_str(json).unwrap();
assert_eq!(
result.signature,
"304402204EF0AFB78AC23ED1C472E74F4299C0C21F1B21D07EFC0A3838A420F\
76D783A400220154FB11B6F54320666E4C36CA7F686C16A3A0456800BBC43746\
F34AF50290064"
);
assert_eq!(result.credentials, None);
}
#[test]
fn test_channel_authorize_serialize() {
let auth = ChannelAuthorize {
signature: "304402204EF0AFB78AC23ED1C472E74F4299C0C21F1B21D07EF\
C0A3838A420F76D783A400220154FB11B6F54320666E4C36CA7\
F686C16A3A0456800BBC43746F34AF50290064"
.into(),
credentials: None,
};
let json = serde_json::to_string(&auth).unwrap();
let expected = r#"{"signature":"304402204EF0AFB78AC23ED1C472E74F4299C0C21F1B21D07EFC0A3838A420F76D783A400220154FB11B6F54320666E4C36CA7F686C16A3A0456800BBC43746F34AF50290064"}"#;
assert_eq!(json, expected);
}
}