openshift_openapi/v4_5/api/image/v1/
signature_subject.rs

1// Generated from definition com.github.openshift.api.image.v1.SignatureSubject
2
3/// SignatureSubject holds information about a person or entity who created the signature.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct SignatureSubject {
6    /// Common name (e.g. openshift-signing-service).
7    pub common_name: Option<String>,
8
9    /// Organization name.
10    pub organization: Option<String>,
11
12    /// If present, it is a human readable key id of public key belonging to the subject used to verify image signature. It should contain at least 64 lowest bits of public key's fingerprint (e.g. 0x685ebe62bf278440).
13    pub public_key_id: String,
14}
15
16impl<'de> serde::Deserialize<'de> for SignatureSubject {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
18        #[allow(non_camel_case_types)]
19        enum Field {
20            Key_common_name,
21            Key_organization,
22            Key_public_key_id,
23            Other,
24        }
25
26        impl<'de> serde::Deserialize<'de> for Field {
27            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
28                struct Visitor;
29
30                impl<'de> serde::de::Visitor<'de> for Visitor {
31                    type Value = Field;
32
33                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34                        f.write_str("field identifier")
35                    }
36
37                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
38                        Ok(match v {
39                            "commonName" => Field::Key_common_name,
40                            "organization" => Field::Key_organization,
41                            "publicKeyID" => Field::Key_public_key_id,
42                            _ => Field::Other,
43                        })
44                    }
45                }
46
47                deserializer.deserialize_identifier(Visitor)
48            }
49        }
50
51        struct Visitor;
52
53        impl<'de> serde::de::Visitor<'de> for Visitor {
54            type Value = SignatureSubject;
55
56            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57                f.write_str("SignatureSubject")
58            }
59
60            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
61                let mut value_common_name: Option<String> = None;
62                let mut value_organization: Option<String> = None;
63                let mut value_public_key_id: Option<String> = None;
64
65                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
66                    match key {
67                        Field::Key_common_name => value_common_name = serde::de::MapAccess::next_value(&mut map)?,
68                        Field::Key_organization => value_organization = serde::de::MapAccess::next_value(&mut map)?,
69                        Field::Key_public_key_id => value_public_key_id = Some(serde::de::MapAccess::next_value(&mut map)?),
70                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
71                    }
72                }
73
74                Ok(SignatureSubject {
75                    common_name: value_common_name,
76                    organization: value_organization,
77                    public_key_id: value_public_key_id.ok_or_else(|| serde::de::Error::missing_field("publicKeyID"))?,
78                })
79            }
80        }
81
82        deserializer.deserialize_struct(
83            "SignatureSubject",
84            &[
85                "commonName",
86                "organization",
87                "publicKeyID",
88            ],
89            Visitor,
90        )
91    }
92}
93
94impl serde::Serialize for SignatureSubject {
95    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
96        let mut state = serializer.serialize_struct(
97            "SignatureSubject",
98            1 +
99            self.common_name.as_ref().map_or(0, |_| 1) +
100            self.organization.as_ref().map_or(0, |_| 1),
101        )?;
102        if let Some(value) = &self.common_name {
103            serde::ser::SerializeStruct::serialize_field(&mut state, "commonName", value)?;
104        }
105        if let Some(value) = &self.organization {
106            serde::ser::SerializeStruct::serialize_field(&mut state, "organization", value)?;
107        }
108        serde::ser::SerializeStruct::serialize_field(&mut state, "publicKeyID", &self.public_key_id)?;
109        serde::ser::SerializeStruct::end(state)
110    }
111}