asn1_rs/asn1_types/
end_of_content.rs

1use crate::{Any, Error, Result, Tag, Tagged};
2use core::convert::TryFrom;
3
4/// End-of-contents octets
5///
6/// `EndOfContent` is not a BER type, but represents a marked to indicate the end of contents
7/// of an object, when the length is `Indefinite` (see X.690 section 8.1.5).
8///
9/// This type cannot exist in DER, and so provides no `FromDer`/`ToDer` implementation.
10#[derive(Debug)]
11pub struct EndOfContent {}
12
13impl Default for EndOfContent {
14    fn default() -> Self {
15        Self::new()
16    }
17}
18
19impl EndOfContent {
20    pub const fn new() -> Self {
21        EndOfContent {}
22    }
23}
24
25impl<'a> TryFrom<Any<'a>> for EndOfContent {
26    type Error = Error;
27
28    fn try_from(any: Any<'a>) -> Result<EndOfContent> {
29        TryFrom::try_from(&any)
30    }
31}
32
33impl<'a, 'b> TryFrom<&'b Any<'a>> for EndOfContent {
34    type Error = Error;
35
36    fn try_from(any: &'b Any<'a>) -> Result<EndOfContent> {
37        any.tag().assert_eq(Self::TAG)?;
38        if !any.header.length.is_null() {
39            return Err(Error::InvalidLength);
40        }
41        Ok(EndOfContent {})
42    }
43}
44
45impl Tagged for EndOfContent {
46    const TAG: Tag = Tag::EndOfContent;
47}
48
49// impl ToDer for EndOfContent {
50//     fn to_der_len(&self) -> Result<usize> {
51//         Ok(2)
52//     }
53
54//     fn write_der_header(&self, writer: &mut dyn std::io::Write) -> crate::SerializeResult<usize> {
55//         writer.write(&[Self::TAG.0 as u8, 0x00]).map_err(Into::into)
56//     }
57
58//     fn write_der_content(&self, _writer: &mut dyn std::io::Write) -> crate::SerializeResult<usize> {
59//         Ok(0)
60//     }
61// }