Skip to content

Commit f4b478e

Browse files
committed
add new function and derives to SequenceRef
1 parent 1131521 commit f4b478e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

der/src/asn1/sequence.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ impl<'a, T> Sequence<'a> for Box<T> where T: Sequence<'a> {}
2828
/// DER-encoded `SEQUENCE`.
2929
///
3030
/// This is a zero-copy reference type which borrows from the input data.
31+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
3132
pub struct SequenceRef<'a> {
3233
/// Body of the `SEQUENCE`.
3334
body: &'a BytesRef,
3435
}
3536

3637
impl<'a> SequenceRef<'a> {
38+
/// Create a new [`SequenceRef`] from the provided DER bytes.
39+
pub fn new(bytes: &'a [u8]) -> Result<Self> {
40+
Ok(Self {
41+
body: &BytesRef::new(bytes)?,
42+
})
43+
}
44+
3745
/// Borrow the inner byte slice.
3846
pub fn as_bytes(&self) -> &'a [u8] {
3947
self.body.as_slice()

0 commit comments

Comments
 (0)