3
3
use crate :: { AlgorithmIdentifier , Error , Result } ;
4
4
use core:: cmp:: Ordering ;
5
5
use der:: {
6
- asn1:: { AnyRef , BitStringRef } ,
6
+ asn1:: { AnyRef , BitString , BitStringRef } ,
7
7
Choice , Decode , DecodeValue , DerOrd , Encode , Header , Reader , Sequence , ValueOrd ,
8
8
} ;
9
9
23
23
use der:: pem:: PemLabel ;
24
24
25
25
/// [`SubjectPublicKeyInfo`] with [`AnyRef`] algorithm parameters.
26
- pub type SubjectPublicKeyInfoRef < ' a > = SubjectPublicKeyInfo < ' a , AnyRef < ' a > > ;
26
+ pub type SubjectPublicKeyInfoRef < ' a > = SubjectPublicKeyInfo < AnyRef < ' a > > ;
27
27
28
28
/// X.509 `SubjectPublicKeyInfo` (SPKI) as defined in [RFC 5280 § 4.1.2.7].
29
29
///
@@ -37,23 +37,23 @@ pub type SubjectPublicKeyInfoRef<'a> = SubjectPublicKeyInfo<'a, AnyRef<'a>>;
37
37
/// ```
38
38
///
39
39
/// [RFC 5280 § 4.1.2.7]: https://tools.ietf.org/html/rfc5280#section-4.1.2.7
40
- #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
41
- pub struct SubjectPublicKeyInfo < ' a , Params > {
40
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
41
+ pub struct SubjectPublicKeyInfo < Params > {
42
42
/// X.509 [`AlgorithmIdentifier`] for the public key type
43
43
pub algorithm : AlgorithmIdentifier < Params > ,
44
44
45
45
/// Public key data
46
- pub subject_public_key : & ' a [ u8 ] ,
46
+ pub subject_public_key : BitString ,
47
47
}
48
48
49
- impl < ' a , Params > SubjectPublicKeyInfo < ' a , Params > {
49
+ impl < Params > SubjectPublicKeyInfo < Params > {
50
50
/// Get a [`BitString`] representing the `subject_public_key`
51
- fn bitstring ( & self ) -> der :: Result < BitStringRef < ' a > > {
52
- BitStringRef :: from_bytes ( self . subject_public_key )
51
+ fn bitstring < ' a > ( & ' a self ) -> BitStringRef < ' a > {
52
+ BitStringRef :: from ( & self . subject_public_key )
53
53
}
54
54
}
55
55
56
- impl < ' a , Params > SubjectPublicKeyInfo < ' a , Params >
56
+ impl < ' a , Params > SubjectPublicKeyInfo < Params >
57
57
where
58
58
Params : Choice < ' a > + Encode ,
59
59
{
@@ -84,35 +84,33 @@ where
84
84
}
85
85
}
86
86
87
- impl < ' a , Params > DecodeValue < ' a > for SubjectPublicKeyInfo < ' a , Params >
87
+ impl < ' a , Params > DecodeValue < ' a > for SubjectPublicKeyInfo < Params >
88
88
where
89
89
Params : Choice < ' a > + Encode ,
90
90
{
91
91
fn decode_value < R : Reader < ' a > > ( reader : & mut R , header : Header ) -> der:: Result < Self > {
92
92
reader. read_nested ( header. length , |reader| {
93
93
Ok ( Self {
94
94
algorithm : reader. decode ( ) ?,
95
- subject_public_key : BitStringRef :: decode ( reader) ?
96
- . as_bytes ( )
97
- . ok_or_else ( || der:: Tag :: BitString . value_error ( ) ) ?,
95
+ subject_public_key : BitString :: decode ( reader) ?,
98
96
} )
99
97
} )
100
98
}
101
99
}
102
100
103
- impl < ' a , Params > Sequence < ' a > for SubjectPublicKeyInfo < ' a , Params >
101
+ impl < ' a , Params > Sequence < ' a > for SubjectPublicKeyInfo < Params >
104
102
where
105
103
Params : Choice < ' a > + Encode ,
106
104
{
107
105
fn fields < F , T > ( & self , f : F ) -> der:: Result < T >
108
106
where
109
107
F : FnOnce ( & [ & dyn Encode ] ) -> der:: Result < T > ,
110
108
{
111
- f ( & [ & self . algorithm , & self . bitstring ( ) ? ] )
109
+ f ( & [ & self . algorithm , & self . bitstring ( ) ] )
112
110
}
113
111
}
114
112
115
- impl < ' a , Params > TryFrom < & ' a [ u8 ] > for SubjectPublicKeyInfo < ' a , Params >
113
+ impl < ' a , Params > TryFrom < & ' a [ u8 ] > for SubjectPublicKeyInfo < Params >
116
114
where
117
115
Params : Choice < ' a > + Encode ,
118
116
{
@@ -123,46 +121,46 @@ where
123
121
}
124
122
}
125
123
126
- impl < ' a , Params > ValueOrd for SubjectPublicKeyInfo < ' a , Params >
124
+ impl < ' a , Params > ValueOrd for SubjectPublicKeyInfo < Params >
127
125
where
128
126
Params : Choice < ' a > + DerOrd + Encode ,
129
127
{
130
128
fn value_cmp ( & self , other : & Self ) -> der:: Result < Ordering > {
131
129
match self . algorithm . der_cmp ( & other. algorithm ) ? {
132
- Ordering :: Equal => self . bitstring ( ) ? . der_cmp ( & other. bitstring ( ) ? ) ,
130
+ Ordering :: Equal => self . bitstring ( ) . der_cmp ( & other. bitstring ( ) ) ,
133
131
other => Ok ( other) ,
134
132
}
135
133
}
136
134
}
137
135
138
136
#[ cfg( feature = "alloc" ) ]
139
137
#[ cfg_attr( docsrs, doc( cfg( feature = "alloc" ) ) ) ]
140
- impl < ' a , Params > TryFrom < SubjectPublicKeyInfo < ' a , Params > > for Document
138
+ impl < ' a , Params > TryFrom < SubjectPublicKeyInfo < Params > > for Document
141
139
where
142
140
Params : Choice < ' a > + Encode ,
143
141
{
144
142
type Error = Error ;
145
143
146
- fn try_from ( spki : SubjectPublicKeyInfo < ' a , Params > ) -> Result < Document > {
144
+ fn try_from ( spki : SubjectPublicKeyInfo < Params > ) -> Result < Document > {
147
145
Self :: try_from ( & spki)
148
146
}
149
147
}
150
148
151
149
#[ cfg( feature = "alloc" ) ]
152
150
#[ cfg_attr( docsrs, doc( cfg( feature = "alloc" ) ) ) ]
153
- impl < ' a , Params > TryFrom < & SubjectPublicKeyInfo < ' a , Params > > for Document
151
+ impl < ' a , Params > TryFrom < & SubjectPublicKeyInfo < Params > > for Document
154
152
where
155
153
Params : Choice < ' a > + Encode ,
156
154
{
157
155
type Error = Error ;
158
156
159
- fn try_from ( spki : & SubjectPublicKeyInfo < ' a , Params > ) -> Result < Document > {
157
+ fn try_from ( spki : & SubjectPublicKeyInfo < Params > ) -> Result < Document > {
160
158
Ok ( Self :: encode_msg ( spki) ?)
161
159
}
162
160
}
163
161
164
162
#[ cfg( feature = "pem" ) ]
165
163
#[ cfg_attr( docsrs, doc( cfg( feature = "pem" ) ) ) ]
166
- impl < Params > PemLabel for SubjectPublicKeyInfo < ' _ , Params > {
164
+ impl < Params > PemLabel for SubjectPublicKeyInfo < Params > {
167
165
const PEM_LABEL : & ' static str = "PUBLIC KEY" ;
168
166
}
0 commit comments