Commit 93ceba1 1 parent be54eb2 commit 93ceba1 Copy full SHA for 93ceba1
File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,22 @@ impl<T: Clone> NonEmptyVec<T> {
58
58
}
59
59
}
60
60
61
+ impl < T : Clone > NonEmptyVec < T > {
62
+ pub fn try_from_iter < I : IntoIterator < Item = T > > ( iter : I ) -> Result < Self , Error > {
63
+ let mut v = Vec :: new ( ) ;
64
+ let mut iter = iter. into_iter ( ) ;
65
+ if let Some ( t) = iter. next ( ) {
66
+ v. push ( t) ;
67
+ } else {
68
+ return Err ( Error :: Empty ) ;
69
+ }
70
+ for t in iter {
71
+ v. push ( t) ;
72
+ }
73
+ Ok ( NonEmptyVec ( v) )
74
+ }
75
+ }
76
+
61
77
impl < T : Clone > TryFrom < Vec < T > > for NonEmptyVec < T > {
62
78
type Error = Error ;
63
79
Original file line number Diff line number Diff line change
1
+ use crate :: definitions:: helpers:: non_empty_vec;
1
2
use crate :: definitions:: helpers:: NonEmptyVec ;
2
3
use crate :: definitions:: x509:: error:: Error as X509Error ;
3
4
use crate :: definitions:: x509:: trust_anchor:: check_validity_period;
@@ -77,6 +78,22 @@ impl From<NonEmptyVec<X509>> for X5Chain {
77
78
}
78
79
}
79
80
81
+ impl TryFrom < Vec < X509 > > for X5Chain {
82
+ type Error = non_empty_vec:: Error ;
83
+
84
+ fn try_from ( v : Vec < X509 > ) -> Result < Self , Self :: Error > {
85
+ NonEmptyVec :: try_from_iter ( v. into_iter ( ) ) . map ( Self )
86
+ }
87
+ }
88
+
89
+ impl TryFrom < Vec < Vec < u8 > > > for X5Chain {
90
+ type Error = non_empty_vec:: Error ;
91
+
92
+ fn try_from ( v : Vec < Vec < u8 > > ) -> Result < Self , Self :: Error > {
93
+ NonEmptyVec :: try_from_iter ( v. into_iter ( ) . map ( |bytes| X509 { bytes } ) ) . map ( Self )
94
+ }
95
+ }
96
+
80
97
impl X5Chain {
81
98
pub fn builder ( ) -> Builder {
82
99
Builder :: default ( )
@@ -124,6 +141,8 @@ impl X5Chain {
124
141
}
125
142
}
126
143
144
+ /// Returns the first certificate in the x.509 certificate chain,
145
+ /// which is expected be the reader's certificate.
127
146
pub fn get_signer_key ( & self ) -> Result < VerifyingKey , X509Error > {
128
147
let leaf = self . 0 . first ( ) . ok_or ( X509Error :: CborDecodingError ) ?;
129
148
leaf. public_key ( ) . map ( |key| key. into ( ) )
You can’t perform that action at this time.
0 commit comments