1616use alloc:: string:: String ;
1717#[ cfg( feature = "alloc" ) ]
1818use core:: fmt;
19+ use core:: mem;
1920
2021use crate :: der:: { self , FromDer } ;
2122use crate :: error:: { DerTypeId , Error } ;
@@ -53,20 +54,19 @@ pub(crate) fn check_name_constraints(
5354 let excluded_subtrees = parse_subtrees ( constraints, der:: Tag :: ContextSpecificConstructed1 ) ?;
5455
5556 for path in path. iter ( ) {
56- let result = NameIterator :: new ( Some ( path. cert . subject ) , path. cert . subject_alt_name )
57- . find_map ( |result| {
58- let name = match result {
59- Ok ( name) => name,
60- Err ( err) => return Some ( Err ( err) ) ,
61- } ;
57+ let result = NameIterator :: new ( path. cert . subject_alt_name , true ) . find_map ( |result| {
58+ let name = match result {
59+ Ok ( name) => name,
60+ Err ( err) => return Some ( Err ( err) ) ,
61+ } ;
6262
63- check_presented_id_conforms_to_constraints (
64- name,
65- permitted_subtrees,
66- excluded_subtrees,
67- budget,
68- )
69- } ) ;
63+ check_presented_id_conforms_to_constraints (
64+ name,
65+ permitted_subtrees,
66+ excluded_subtrees,
67+ budget,
68+ )
69+ } ) ;
7070
7171 if let Some ( Err ( err) ) = result {
7272 return Err ( err) ;
@@ -203,19 +203,17 @@ enum Subtrees {
203203
204204pub ( crate ) struct NameIterator < ' a > {
205205 subject_alt_name : Option < untrusted:: Reader < ' a > > ,
206- subject_directory_name : Option < untrusted :: Input < ' a > > ,
206+ directory_name : bool ,
207207}
208208
209209impl < ' a > NameIterator < ' a > {
210210 pub ( crate ) fn new (
211- subject : Option < untrusted:: Input < ' a > > ,
212211 subject_alt_name : Option < untrusted:: Input < ' a > > ,
212+ directory_name : bool ,
213213 ) -> Self {
214- NameIterator {
214+ Self {
215215 subject_alt_name : subject_alt_name. map ( untrusted:: Reader :: new) ,
216-
217- // If `subject` is present, we always consider it as a `DirectoryName`.
218- subject_directory_name : subject,
216+ directory_name,
219217 }
220218 }
221219}
@@ -240,14 +238,14 @@ impl<'a> Iterator for NameIterator<'a> {
240238
241239 // Make sure we don't yield any items after this error.
242240 self . subject_alt_name = None ;
243- self . subject_directory_name = None ;
241+ self . directory_name = false ;
244242 return Some ( Err ( err) ) ;
245243 } else {
246244 self . subject_alt_name = None ;
247245 }
248246 }
249247
250- if self . subject_directory_name . take ( ) . is_some ( ) {
248+ if mem :: take ( & mut self . directory_name ) {
251249 return Some ( Ok ( GeneralName :: DirectoryName ) ) ;
252250 }
253251
0 commit comments