Skip to content
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
28 changes: 14 additions & 14 deletions der/src/asn1/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ use crate::{
DecodeValue, EncodeValue, Error, FixedTag, Header, Length, Reader, Result, Tag, Tagged, Writer,
asn1::AnyRef, ord::OrdIsValueOrd,
};
use const_oid::ObjectIdentifier;
use const_oid::{ObjectIdentifier, ObjectIdentifierRef};

#[cfg(feature = "alloc")]
use super::Any;

impl<'a> DecodeValue<'a> for ObjectIdentifier {
impl<'a, const MAX_SIZE: usize> DecodeValue<'a> for ObjectIdentifier<MAX_SIZE> {
type Error = Error;

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
let mut buf = [0u8; ObjectIdentifier::MAX_SIZE];
let mut buf = [0u8; MAX_SIZE];
let slice = buf
.get_mut(..header.length.try_into()?)
.ok_or_else(|| Self::TAG.length_error())?;

let actual_len = reader.read_into(slice)?.len();
debug_assert_eq!(actual_len, header.length.try_into()?);
Ok(Self::from_bytes(slice)?)
Ok(ObjectIdentifierRef::from_bytes(slice)?.try_into()?)
}
}

impl EncodeValue for ObjectIdentifier {
impl<const MAX_SIZE: usize> EncodeValue for ObjectIdentifier<MAX_SIZE> {
fn value_len(&self) -> Result<Length> {
Length::try_from(self.as_bytes().len())
}
Expand All @@ -34,14 +34,14 @@ impl EncodeValue for ObjectIdentifier {
}
}

impl FixedTag for ObjectIdentifier {
impl<const MAX_SIZE: usize> FixedTag for ObjectIdentifier<MAX_SIZE> {
const TAG: Tag = Tag::ObjectIdentifier;
}

impl OrdIsValueOrd for ObjectIdentifier {}
impl<const MAX_SIZE: usize> OrdIsValueOrd for ObjectIdentifier<MAX_SIZE> {}

impl<'a> From<&'a ObjectIdentifier> for AnyRef<'a> {
fn from(oid: &'a ObjectIdentifier) -> AnyRef<'a> {
impl<'a, const MAX_SIZE: usize> From<&'a ObjectIdentifier<MAX_SIZE>> for AnyRef<'a> {
fn from(oid: &'a ObjectIdentifier<MAX_SIZE>) -> AnyRef<'a> {
// Note: ensuring an infallible conversion is possible relies on the
// invariant that `const_oid::MAX_LEN <= Length::max()`.
//
Expand All @@ -56,18 +56,18 @@ impl<'a> From<&'a ObjectIdentifier> for AnyRef<'a> {
}

#[cfg(feature = "alloc")]
impl From<ObjectIdentifier> for Any {
fn from(oid: ObjectIdentifier) -> Any {
impl<const MAX_SIZE: usize> From<ObjectIdentifier<MAX_SIZE>> for Any {
fn from(oid: ObjectIdentifier<MAX_SIZE>) -> Any {
AnyRef::from(&oid).into()
}
}

impl TryFrom<AnyRef<'_>> for ObjectIdentifier {
impl<const MAX_SIZE: usize> TryFrom<AnyRef<'_>> for ObjectIdentifier<MAX_SIZE> {
type Error = Error;

fn try_from(any: AnyRef<'_>) -> Result<ObjectIdentifier> {
fn try_from(any: AnyRef<'_>) -> Result<ObjectIdentifier<MAX_SIZE>> {
any.tag().assert_eq(Tag::ObjectIdentifier)?;
Ok(ObjectIdentifier::from_bytes(any.value())?)
Ok(ObjectIdentifierRef::from_bytes(any.value())?.try_into()?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion x509-cert/tests/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn reencode_cert() {

#[test]
fn decode_oversized_oids() {
let o1parse = ObjectIdentifier::from_der(&hex!(
let o1parse: ObjectIdentifier = Decode::from_der(&hex!(
"06252B060104018237150885C8B86B87AFF00383A99F3C96C34081ADE6494D82B0E91D85B2873D"
))
.unwrap();
Expand Down