Skip to content
Open
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
12 changes: 10 additions & 2 deletions der/src/asn1/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//! `SEQUENCE`s to Rust structs.

use crate::{
BytesRef, DecodeValue, EncodeValue, Error, FixedTag, Header, Length, Reader, Result, Tag,
Writer,
BytesRef, DecodeValue, EncodeValue, Error, ErrorKind, FixedTag, Header, Length, Reader, Result,
Tag, Writer,
};

#[cfg(feature = "alloc")]
Expand All @@ -28,12 +28,20 @@ impl<'a, T> Sequence<'a> for Box<T> where T: Sequence<'a> {}
/// DER-encoded `SEQUENCE`.
///
/// This is a zero-copy reference type which borrows from the input data.
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct SequenceRef<'a> {
/// Body of the `SEQUENCE`.
body: &'a BytesRef,
}

impl<'a> SequenceRef<'a> {
/// Create a new [`SequenceRef`] from the provided DER bytes.
pub fn new(slice: &'a [u8]) -> Result<Self> {
BytesRef::new(slice)
.map(|body| Self { body })
.map_err(|_| ErrorKind::Length { tag: Self::TAG }.into())
}

/// Borrow the inner byte slice.
pub fn as_bytes(&self) -> &'a [u8] {
self.body.as_slice()
Expand Down