[−][src]Struct bcder::string::OctetString
An octet string value.
An octet string is a sequence of octets, i.e., a glorified [u8]
. Basic
Encoding Rules, however, allow this sequence to be broken up into chunks
that are encoded separatedly to allow for very large octet strings and
cases where one doesn’t yet know the length of the string.
In order to avoid unnecessary allocations, this type wraps the raw content
octets of a BER encoded octet string. As a consequence, assembling the
complete string may actually be costly and should only be done if really
necessary. As an alternative, there is an iterator over the parts via the
iter
method or the IntoIterator
trait as well as an iterator over the
individual octets via the octets
method.
Octet strings are sometimes used to store BER encoded data. The
OctetStringSource
type, accessible via the to_source
method, provides
an implementation of the Source
trait to run a decoder on.
BER Encoding
Octet strings are either encoded as a primitive or a constructed value. In the primitive form, the content octets are the string’s octets. In a constructed form, the content is a sequence of encoded octets strings which in turn may be primitive or constructed. In this case, the string’s octets are the concatenation of all the content octets of the primitive forms in the order as encountered.
In CER, the string must use the primitive form if it is less than 1000 octets long and the constructed form otherwise. The constructed form must consists of a sequence of primitive values each exactly with a 1000 octets of content except for the last one.
In DER, only the primitive form is allowed.
Methods
impl OctetString
[src]
pub fn new(bytes: Bytes) -> Self
[src]
Creates an octet string from a Bytes value.
ⓘImportant traits for OctetStringIter<'a>pub fn iter(&self) -> OctetStringIter
[src]
Returns an iterator over the parts of the octet string.
The iterator will produce &[u8]
which, when appended produce the
complete content of the octet string.
ⓘImportant traits for OctetStringOctets<'a>pub fn octets(&self) -> OctetStringOctets
[src]
Returns an iterator over the individual octets of the string.
pub fn as_slice(&self) -> Option<&[u8]>
[src]
Returns a reference to the complete content if possible.
The method will return a bytes slice of the content if the octet
string was encoded as a single primitive value or None
otherwise.
This is guaranteed to return some slice if the value was produced by decoding in DER mode.
pub fn to_bytes(&self) -> Bytes
[src]
Produces a bytes value with the string’s content.
If the octet string was encoded as a single primitive value, the method will simply clone the content. Otherwise it will produce an entirely new bytes value from the concatenated content of all the primitive values.
pub fn into_bytes(self) -> Bytes
[src]
Converts the octet string into bytes value.
If the octet string was encoded as a single primitive value, the method will simply return the content. Otherwise it will produce an entirely new bytes value from the concatenated content of all the primitive values.
pub fn len(&self) -> usize
[src]
Returns the length of the content.
This is not the length of the encoded value but of the actual octet string.
pub fn is_empty(&self) -> bool
[src]
Returns whether the content is empty.
pub fn to_source(&self) -> OctetStringSource
[src]
Creates a source that can be used to decode the string’s content.
The returned value contains a clone of the string (which, because of
the use of Bytes
is rather cheap) that implements the Source
trait and thus can be used to decode the string’s content.
impl OctetString
[src]
pub fn take_from<S: Source>(cons: &mut Constructed<S>) -> Result<Self, S::Err>
[src]
Takes a single octet string value from constructed value content.
If there is no next value, if the next value does not have the tag
Tag::OCTET_STRING
, or if it doesn’t contain a correctly encoded
octet string, a malformed error is returned.
pub fn from_content<S: Source>(content: &mut Content<S>) -> Result<Self, S::Err>
[src]
Takes an octet string value from content.
pub fn encode(self) -> impl Values
[src]
Returns a value encoder for the octet string using the natural tag.
pub fn encode_as(self, tag: Tag) -> impl Values
[src]
Returns a value encoder for the octet string using the given tag.
pub fn encode_ref<'a>(&'a self) -> impl Values + 'a
[src]
Returns a value encoder for the octet string using the natural tag.
pub fn encode_ref_as<'a>(&'a self, tag: Tag) -> impl Values + 'a
[src]
Returns a value encoder for the octet string using the given tag.
pub fn encode_wrapped<V: Values>(mode: Mode, values: V) -> impl Values
[src]
Returns a value encoder that wraps values into an octet string.
This function allows an octet string wrapping some values to be created without having to first create the octet string.
pub fn encode_slice<T>(value: T) -> OctetSliceEncoder<T>
[src]
Returns a value encoder that encodes a bytes slice as an octet string.
pub fn encode_slice_as<T>(value: T, tag: Tag) -> OctetSliceEncoder<T>
[src]
Returns a value encoder that encodes a bytes slice as an octet string.
Trait Implementations
impl<L: CharSet> AsRef<OctetString> for RestrictedString<L>
[src]
fn as_ref(&self) -> &OctetString
[src]
impl AsRef<OctetString> for OctetString
[src]
impl Clone for OctetString
[src]
fn clone(&self) -> OctetString
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for OctetString
[src]
impl Eq for OctetString
[src]
impl Hash for OctetString
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> IntoIterator for &'a OctetString
[src]
type Item = &'a [u8]
The type of the elements being iterated over.
type IntoIter = OctetStringIter<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl Ord for OctetString
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<OctetString> for OctetString
[src]
fn eq(&self, other: &OctetString) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: AsRef<[u8]>> PartialEq<T> for OctetString
[src]
impl PartialOrd<OctetString> for OctetString
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: AsRef<[u8]>> PartialOrd<T> for OctetString
[src]
Auto Trait Implementations
impl RefUnwindSafe for OctetString
impl Send for OctetString
impl Sync for OctetString
impl Unpin for OctetString
impl UnwindSafe for OctetString
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,