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

Simplify AlgorithmIdentifier type #6

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustls-pki-types"
version = "0.1.2"
version = "0.2.0"
edition = "2021"
rust-version = "1.60"
license = "MIT OR Apache-2.0"
Expand Down
29 changes: 8 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,45 +365,32 @@ pub struct InvalidSignature;
/// ]
/// );
/// ```
#[derive(Debug, Clone, PartialEq)]
pub struct AlgorithmIdentifier<'a>(Der<'a>);
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AlgorithmIdentifier(&'static [u8]);

impl<'a> AlgorithmIdentifier<'a> {
impl AlgorithmIdentifier {
/// Makes a new `AlgorithmIdentifier` from a static octet slice.
///
/// This does not validate the contents of the slice.
pub const fn from_slice(bytes: &'a [u8]) -> Self {
Self(Der::from_slice(bytes))
pub const fn from_slice(bytes: &'static [u8]) -> Self {
Self(bytes)
}
}

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

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

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

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

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

/// DER-encoded data, either owned or borrowed
///
/// This wrapper type is used to represent DER-encoded data in a way that is agnostic to whether
Expand Down