Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/der/src/asn1/sequence.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / der / src / asn1 / sequence.rs` 53 lines ยท 1387 bytes Raw Blame History 1 //! The [`Sequence`] trait simplifies writing decoders/encoders which map ASN.1 2 //! `SEQUENCE`s to Rust structs. 3 4 use crate::{ 5 BytesRef, DecodeValue, EncodeValue, FixedTag, Header, Length, Reader, Result, Tag, Writer, 6 }; 7 8 #[cfg(feature = "alloc")] 9 use alloc::boxed::Box; 10 11 /// Marker trait for ASN.1 `SEQUENCE`s. 12 /// 13 /// This is mainly used for custom derive. 14 pub trait Sequence<'a>: DecodeValue<'a> + EncodeValue {} 15 16 impl<'a, S> FixedTag for S 17 where 18 S: Sequence<'a>, 19 { 20 const TAG: Tag = Tag::Sequence; 21 } 22 23 #[cfg(feature = "alloc")] 24 impl<'a, T> Sequence<'a> for Box where T: Sequence<'a> {} 25 26 /// The [`SequenceRef`] type provides raw access to the octets which comprise a 27 /// DER-encoded `SEQUENCE`. 28 /// 29 /// This is a zero-copy reference type which borrows from the input data. 30 pub struct SequenceRef<'a> { 31 /// Body of the `SEQUENCE`. 32 body: BytesRef<'a>, 33 } 34 35 impl<'a> DecodeValue<'a> for SequenceRef<'a> { 36 fn decode_value>(reader: &mut R, header: Header) -> Result { 37 Ok(Self { 38 body: BytesRef::decode_value(reader, header)?, 39 }) 40 } 41 } 42 43 impl EncodeValue for SequenceRef<'_> { 44 fn value_len(&self) -> Result { 45 Ok(self.body.len()) 46 } 47 48 fn encode_value(&self, writer: &mut impl Writer) -> Result<()> { 49 self.body.encode_value(writer) 50 } 51 } 52 53 impl<'a> Sequence<'a> for SequenceRef<'a> {}