cryptographic_message_syntax/asn1/
rfc4210.rs1use bcder::{
8 decode::{Constructed, DecodeError, Source},
9 encode::{self, Values},
10 Tag, Utf8String,
11};
12
13#[derive(Clone, Debug, Eq, PartialEq)]
19pub struct PkiFreeText(Vec<Utf8String>);
20
21impl PkiFreeText {
22 pub fn take_opt_from<S: Source>(
23 cons: &mut Constructed<S>,
24 ) -> Result<Option<Self>, DecodeError<S::Error>> {
25 cons.take_opt_sequence(|cons| Self::from_sequence(cons))
26 }
27
28 pub fn take_from<S: Source>(cons: &mut Constructed<S>) -> Result<Self, DecodeError<S::Error>> {
29 cons.take_sequence(|cons| Self::from_sequence(cons))
30 }
31
32 pub fn from_sequence<S: Source>(
33 cons: &mut Constructed<S>,
34 ) -> Result<Self, DecodeError<S::Error>> {
35 let mut res = vec![];
36
37 while let Some(s) = cons.take_opt_value_if(Tag::UTF8_STRING, |content| {
38 Utf8String::from_content(content)
39 })? {
40 res.push(s);
41 }
42
43 Ok(Self(res))
44 }
45
46 pub fn encode_ref(&self) -> impl Values + '_ {
47 encode::sequence(encode::slice(&self.0, |x| x.clone().encode()))
48 }
49}