pub trait EncodeValue {
// Required methods
fn value_len(&self) -> Result<Length, Error>;
fn encode_value(&self, writer: &mut impl Writer) -> Result<(), Error>;
// Provided method
fn header(&self) -> Result<Header, Error>
where Self: Tagged { ... }
}Available on crate feature
pkcs8 only.Expand description
Encode the value part of a Tag-Length-Value encoded field, sans the [Tag]
and Length.
As opposed to Encode, implementer is expected to write the inner content only,
without the Header.
When EncodeValue is paired with [FixedTag],
it produces a complete TLV ASN.1 DER encoding as Encode trait.
§Example
use der::{Encode, EncodeValue, ErrorKind, FixedTag, Length, Tag, Writer};
/// 1-byte month
struct MyByteMonth(u8);
impl EncodeValue for MyByteMonth {
fn value_len(&self) -> der::Result<Length> {
Ok(Length::new(1))
}
fn encode_value(&self, writer: &mut impl Writer) -> der::Result<()> {
writer.write_byte(self.0)?;
Ok(())
}
}
impl FixedTag for MyByteMonth {
const TAG: Tag = Tag::OctetString;
}
let month = MyByteMonth(9);
let mut buf = [0u8; 16];
let month_der = month.encode_to_slice(&mut buf).expect("month to encode");
assert_eq!(month_der, b"\x04\x01\x09");Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl EncodeValue for bool
impl EncodeValue for bool
Source§impl EncodeValue for i8
impl EncodeValue for i8
Source§impl EncodeValue for i16
impl EncodeValue for i16
Source§impl EncodeValue for i32
impl EncodeValue for i32
Source§impl EncodeValue for i64
impl EncodeValue for i64
Source§impl EncodeValue for i128
impl EncodeValue for i128
Source§impl EncodeValue for str
impl EncodeValue for str
Source§impl EncodeValue for u8
impl EncodeValue for u8
Source§impl EncodeValue for u16
impl EncodeValue for u16
Source§impl EncodeValue for u32
impl EncodeValue for u32
Source§impl EncodeValue for u64
impl EncodeValue for u64
Source§impl EncodeValue for u128
impl EncodeValue for u128
Source§impl EncodeValue for ()
impl EncodeValue for ()
Source§impl EncodeValue for String
Available on crate feature alloc only.
impl EncodeValue for String
Available on crate feature
alloc only.Source§impl<T> EncodeValue for Cow<'_, T>
Available on crate feature alloc only.
impl<T> EncodeValue for Cow<'_, T>
Available on crate feature
alloc only.Source§impl<T> EncodeValue for [T]where
T: Encode,
impl<T> EncodeValue for [T]where
T: Encode,
Source§impl<T> EncodeValue for Box<T>where
T: EncodeValue,
Available on crate feature alloc only.
impl<T> EncodeValue for Box<T>where
T: EncodeValue,
Available on crate feature
alloc only.Source§impl<T> EncodeValue for Vec<T>where
T: Encode,
Available on crate feature alloc only.
impl<T> EncodeValue for Vec<T>where
T: Encode,
Available on crate feature
alloc only.Implementors§
impl EncodeValue for &OctetStringRef
impl EncodeValue for BitString
impl EncodeValue for BitStringRef<'_>
impl EncodeValue for BmpString
impl EncodeValue for GeneralStringRef<'_>
impl EncodeValue for GeneralizedTime
impl EncodeValue for Ia5String
impl EncodeValue for Int
impl EncodeValue for IntRef<'_>
impl EncodeValue for Null
impl EncodeValue for OctetString
impl EncodeValue for PrintableString
impl EncodeValue for SequenceRef
impl EncodeValue for TeletexString
impl EncodeValue for Uint
impl EncodeValue for UintRef<'_>
impl EncodeValue for UtcTime
impl EncodeValue for Any
impl EncodeValue for AnyRef<'_>
impl EncodeValue for DateTime
impl<'a> EncodeValue for Ia5StringRef<'a>
impl<'a> EncodeValue for PrintableStringRef<'a>
impl<'a> EncodeValue for TeletexStringRef<'a>
impl<'a> EncodeValue for Utf8StringRef<'a>
impl<'a> EncodeValue for VideotexStringRef<'a>
impl<'a, Params, Key> EncodeValue for SubjectPublicKeyInfo<Params, Key>
impl<'a, Params, Key, PubKey> EncodeValue for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: EncodeValue + FixedTag,
PubKey: BitStringLike,
impl<Params> EncodeValue for AlgorithmIdentifier<Params>where
Params: Encode,
impl<T> EncodeValue for Application<T>where
T: EncodeValue + Tagged,
impl<T> EncodeValue for ApplicationRef<'_, T>where
T: EncodeValue + Tagged,
impl<T> EncodeValue for ContextSpecific<T>where
T: EncodeValue + Tagged,
impl<T> EncodeValue for ContextSpecificRef<'_, T>where
T: EncodeValue + Tagged,
impl<T> EncodeValue for Private<T>where
T: EncodeValue + Tagged,
impl<T> EncodeValue for PrivateRef<'_, T>where
T: EncodeValue + Tagged,
impl<T> EncodeValue for SetOfVec<T>
Available on crate feature
alloc only.