Skip to content

Commit

Permalink
add const CertificateDer::from_slice
Browse files Browse the repository at this point in the history
This commit adds the ability to construct a `const CertificateDer` by
way of the `const`-friendly `CertificateDer::from_slice()` fn that
accepts a slice of `&[u8]` DER.
  • Loading branch information
cpu committed Aug 6, 2024
1 parent b39d810 commit e8597ba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use std::time::SystemTime;
use web_time::SystemTime;

mod server_name;

pub use server_name::{
AddrParseError, DnsName, InvalidDnsNameError, IpAddr, Ipv4Addr, Ipv6Addr, ServerName,
};
Expand Down Expand Up @@ -465,6 +466,13 @@ impl<'a> From<Vec<u8>> for CertificateSigningRequestDer<'a> {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CertificateDer<'a>(Der<'a>);

impl<'a> CertificateDer<'a> {
/// A const constructor to create a `CertificateDer` from a slice of DER.
pub const fn from_slice(bytes: &'a [u8]) -> Self {
Self(Der::from_slice(bytes))
}
}

impl AsRef<[u8]> for CertificateDer<'_> {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
Expand Down

0 comments on commit e8597ba

Please sign in to comment.