use bcder::{
decode::{Constructed, DecodeError, Source},
encode::{self, Values},
Tag, Utf8String,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PkiFreeText(Vec<Utf8String>);
impl PkiFreeText {
pub fn take_opt_from<S: Source>(
cons: &mut Constructed<S>,
) -> Result<Option<Self>, DecodeError<S::Error>> {
cons.take_opt_sequence(|cons| Self::from_sequence(cons))
}
pub fn take_from<S: Source>(cons: &mut Constructed<S>) -> Result<Self, DecodeError<S::Error>> {
cons.take_sequence(|cons| Self::from_sequence(cons))
}
pub fn from_sequence<S: Source>(
cons: &mut Constructed<S>,
) -> Result<Self, DecodeError<S::Error>> {
let mut res = vec![];
while let Some(s) = cons.take_opt_value_if(Tag::UTF8_STRING, |content| {
Utf8String::from_content(content)
})? {
res.push(s);
}
Ok(Self(res))
}
pub fn encode_ref(&self) -> impl Values + '_ {
encode::sequence(encode::slice(&self.0, |x| x.clone().encode()))
}
}