cyclonedx_rust/common/
attached_text.rs1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3use yaserde_derive::{YaDeserialize, YaSerialize};
4
5#[derive(
6 Clone, Default, Builder, PartialEq, Debug, Serialize, Deserialize, YaSerialize, YaDeserialize,
7)]
8#[yaserde(rename = "text")]
9pub struct AttachedTextType {
10 #[serde(rename = "content-type")]
11 #[yaserde(rename = "content-type", attribute)]
12 pub content_type: Option<String>,
13
14 #[yaserde(attribute)]
15 pub encoding: Option<BomEncoding>,
16
17 #[yaserde(text)]
18 pub value: String,
19}
20
21#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, YaSerialize, YaDeserialize)]
22pub enum BomEncoding {
23 #[serde(rename = "base64")]
24 #[yaserde(rename = "base64")]
25 Base64,
26}
27
28impl Default for BomEncoding {
29 fn default() -> Self {
30 BomEncoding::Base64
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use yaserde::ser::Config;
38
39 #[test]
40 fn print_xml() {
41 let expected: AttachedTextType = AttachedTextTypeBuilder::default()
42 .content_type(Option::from("text/xml".to_string()))
43 .encoding(Option::from(BomEncoding::Base64))
44 .value("content".to_string())
45 .build()
46 .unwrap();
47
48 let parsed = yaserde::ser::to_string_with_config(
49 &expected,
50 &Config {
51 perform_indent: false,
52 write_document_declaration: false,
53 indent_string: None,
54 },
55 )
56 .unwrap();
57
58 let actual: AttachedTextType = yaserde::de::from_str(parsed.as_str()).unwrap();
59
60 assert_eq!(expected, actual);
61 }
62}