Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: 18013-7 MDL Presentation Updates #98

Draft
wants to merge 1 commit into
base: feat/mdoc-auth-crl
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/definitions/helpers/non_empty_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ impl<T: Clone> NonEmptyVec<T> {
}
}

impl<T: Clone> NonEmptyVec<T> {
pub fn try_from_iter<I: IntoIterator<Item = T>>(iter: I) -> Result<Self, Error> {
let mut v = Vec::new();
let mut iter = iter.into_iter();
if let Some(t) = iter.next() {
v.push(t);
} else {
return Err(Error::Empty);
}
for t in iter {
v.push(t);
}
Ok(NonEmptyVec(v))
}
}

impl<T: Clone> TryFrom<Vec<T>> for NonEmptyVec<T> {
type Error = Error;

Expand Down
19 changes: 19 additions & 0 deletions src/definitions/x509/x5chain.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::definitions::helpers::non_empty_vec;
use crate::definitions::helpers::NonEmptyVec;
use crate::definitions::x509::error::Error as X509Error;
use crate::definitions::x509::trust_anchor::check_validity_period;
Expand Down Expand Up @@ -77,6 +78,22 @@ impl From<NonEmptyVec<X509>> for X5Chain {
}
}

impl TryFrom<Vec<X509>> for X5Chain {
type Error = non_empty_vec::Error;

fn try_from(v: Vec<X509>) -> Result<Self, Self::Error> {
NonEmptyVec::try_from_iter(v.into_iter()).map(Self)
}
}

impl TryFrom<Vec<Vec<u8>>> for X5Chain {
type Error = non_empty_vec::Error;

fn try_from(v: Vec<Vec<u8>>) -> Result<Self, Self::Error> {
NonEmptyVec::try_from_iter(v.into_iter().map(|bytes| X509 { bytes })).map(Self)
}
}

impl X5Chain {
pub fn builder() -> Builder {
Builder::default()
Expand Down Expand Up @@ -124,6 +141,8 @@ impl X5Chain {
}
}

/// Returns the first certificate in the x.509 certificate chain,
/// which is expected be the reader's certificate.
pub fn get_signer_key(&self) -> Result<VerifyingKey, X509Error> {
let leaf = self.0.first().ok_or(X509Error::CborDecodingError)?;
leaf.public_key().map(|key| key.into())
Expand Down