Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SubjectPublicKeyInfo DER newtype #47

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,45 @@ impl CertificateDer<'_> {
}
}

/// A DER-encoded SubjectPublicKeyInfo (SPKI), as specified in RFC 5280.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SubjectPublicKeyInfo<'a>(Der<'a>);

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

impl Deref for SubjectPublicKeyInfo<'_> {
type Target = [u8];

fn deref(&self) -> &Self::Target {
self.as_ref()
}
}

impl<'a> From<&'a [u8]> for SubjectPublicKeyInfo<'a> {
fn from(slice: &'a [u8]) -> Self {
Self(Der::from(slice))
}
}

#[cfg(feature = "alloc")]
impl<'a> From<Vec<u8>> for SubjectPublicKeyInfo<'a> {
fn from(vec: Vec<u8>) -> Self {
Self(Der::from(vec))
}
}

impl SubjectPublicKeyInfo<'_> {
/// Converts this SubjectPublicKeyInfo into its owned variant, unfreezing borrowed content (if any)
#[cfg(feature = "alloc")]
pub fn into_owned(self) -> SubjectPublicKeyInfo<'static> {
SubjectPublicKeyInfo(Der(self.0 .0.into_owned()))
}
}

/// A TLS-encoded Encrypted Client Hello (ECH) configuration list (`ECHConfigList`); as specified in
/// [draft-ietf-tls-esni-18 §4](https://datatracker.ietf.org/doc/html/draft-ietf-tls-esni-18#section-4)
#[derive(Clone, Eq, PartialEq)]
Expand Down
Loading