Skip to content

Commit 5f4ec11

Browse files
committed
lib: rm alloc req. for dns_names
With the update to the `dns_names` function in the previous commit we can now make `EndEntity.dns_names` work without requiring `alloc`.
1 parent cd7bbfd commit 5f4ec11

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

src/end_entity.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ impl<'a> EndEntityCert<'a> {
153153
/// This function must not be used to implement custom DNS name verification.
154154
/// Checking that a certificate is valid for a given subject name should always be done with
155155
/// [EndEntityCert::verify_is_valid_for_subject_name].
156-
#[cfg(feature = "alloc")]
157156
pub fn dns_names(&'a self) -> impl Iterator<Item = &'a str> {
158157
subject_name::list_cert_dns_names(self)
159158
}

src/subject_name/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ pub use ip_address::{AddrParseError, IpAddrRef};
2828
pub use ip_address::IpAddr;
2929

3030
mod verify;
31-
#[cfg(feature = "alloc")]
32-
pub(super) use verify::list_cert_dns_names;
33-
pub(super) use verify::{check_name_constraints, verify_cert_subject_name, GeneralName};
31+
pub(super) use verify::{
32+
check_name_constraints, list_cert_dns_names, verify_cert_subject_name, GeneralName,
33+
};

src/subject_name/verify.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1313
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1414

15-
#[cfg(feature = "alloc")]
16-
use alloc::vec::Vec;
17-
18-
use super::dns_name::{self, DnsNameRef};
19-
#[cfg(feature = "alloc")]
20-
use super::dns_name::{GeneralDnsNameRef, WildcardDnsNameRef};
15+
use super::dns_name::{self, DnsNameRef, GeneralDnsNameRef, WildcardDnsNameRef};
2116
use super::ip_address::{self, IpAddrRef};
2217
use super::name::SubjectNameRef;
2318
use crate::der::{self, FromDer};
@@ -317,22 +312,16 @@ impl<'a> Iterator for NameIterator<'a> {
317312
}
318313
}
319314

320-
#[cfg(feature = "alloc")]
321315
pub(crate) fn list_cert_dns_names<'names>(
322316
cert: &'names crate::EndEntityCert<'names>,
323317
) -> impl Iterator<Item = &'names str> {
324318
let cert = &cert.inner();
325-
let mut names = Vec::new();
326-
327-
NameIterator::new(Some(cert.subject), cert.subject_alt_name).for_each(|result| {
328-
let name = match result {
329-
Ok(name) => name,
330-
Err(_) => return,
331-
};
319+
NameIterator::new(Some(cert.subject), cert.subject_alt_name).filter_map(|result| {
320+
let name = result.ok()?;
332321

333322
let presented_id = match name {
334323
GeneralName::DnsName(presented) => presented,
335-
_ => return,
324+
_ => return None,
336325
};
337326

338327
let dns_name = DnsNameRef::try_from_ascii(presented_id.as_slice_less_safe())
@@ -344,12 +333,11 @@ pub(crate) fn list_cert_dns_names<'names>(
344333

345334
// if the name could be converted to a DNS name, add it; otherwise,
346335
// keep going.
347-
if let Ok(name) = dns_name {
348-
names.push(name.into())
336+
match dns_name {
337+
Ok(name) => Some(name.into()),
338+
_ => None,
349339
}
350-
});
351-
352-
names.into_iter()
340+
})
353341
}
354342

355343
// It is *not* valid to derive `Eq`, `PartialEq, etc. for this type. In

0 commit comments

Comments
 (0)