pub trait PrimitiveContent: Sized {
    const TAG: Tag;

    // Required methods
    fn encoded_len(&self, mode: Mode) -> usize;
    fn write_encoded<W: Write>(
        &self,
        mode: Mode,
        target: &mut W
    ) -> Result<(), Error>;

    // Provided methods
    fn to_encoded_bytes(&self, mode: Mode) -> Bytes { ... }
    fn encode(self) -> Primitive<Self> { ... }
    fn encode_as(self, tag: Tag) -> Primitive<Self> { ... }
    fn encode_ref(&self) -> Primitive<&Self> { ... }
    fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self> { ... }
}
Expand description

A type that is encoded as a primitive value.

This trait should be implemented for types that use primitive encoding. It defines, how the content octets of a single primitive value containing a value of the type are to be created. As a consequence, these types gain the encode and encode_as methods from their implementation of this trait.

Note that the trait requires implementing types to be Copy to avoid unnecessary lifetime parameters on the encoder type. For types that aren’t Copy, PrimitiveContent should be implemented on a reference to the type instead.

Required Associated Constants§

source

const TAG: Tag

The natural tag of an encoded value of this type.

Required Methods§

source

fn encoded_len(&self, mode: Mode) -> usize

Returns the length of the encoded content of this type.

source

fn write_encoded<W: Write>( &self, mode: Mode, target: &mut W ) -> Result<(), Error>

Writes the encoded content to a writer.

Provided Methods§

source

fn to_encoded_bytes(&self, mode: Mode) -> Bytes

Encodes the value to bytes (useful when you need to sign a structure)

source

fn encode(self) -> Primitive<Self>

Returns a value encoder for this content using the natural tag.

This is identical to self.encode_as(Self::TAG)

source

fn encode_as(self, tag: Tag) -> Primitive<Self>

Returns a value encoder for this content using the given tag.

The returned value is a content encoder that produces a single primitive BER encoded value. The tag for this value is explicitely given via the tag argument.

source

fn encode_ref(&self) -> Primitive<&Self>

Returns a value encoder for a reference using the natural tag.

source

fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>

Returns a value encoder for a reference using the given tag.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl PrimitiveContent for bool

source§

const TAG: Tag = Tag::BOOLEAN

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for i8

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for i16

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for i32

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for i64

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for i128

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for u8

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for u16

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for u32

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for u64

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for u128

source§

const TAG: Tag = Tag::INTEGER

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl PrimitiveContent for ()

source§

const TAG: Tag = Tag::NULL

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, _: &mut W) -> Result<(), Error>

source§

impl<'a> PrimitiveContent for &'a [u8]

source§

const TAG: Tag = Tag::OCTET_STRING

source§

fn encoded_len(&self, _: Mode) -> usize

source§

fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>

source§

impl<'a, T: PrimitiveContent> PrimitiveContent for &'a T

source§

const TAG: Tag = T::TAG

source§

fn encoded_len(&self, mode: Mode) -> usize

source§

fn write_encoded<W: Write>( &self, mode: Mode, target: &mut W ) -> Result<(), Error>

Implementors§

source§

impl PrimitiveContent for BitString

source§

const TAG: Tag = Tag::BIT_STRING

source§

impl<'a> PrimitiveContent for &'a Integer

source§

const TAG: Tag = Tag::INTEGER

source§

impl<'a> PrimitiveContent for &'a Unsigned

source§

const TAG: Tag = Tag::INTEGER

source§

impl<T: AsRef<[u8]>> PrimitiveContent for Oid<T>

source§

const TAG: Tag = Tag::OID