Struct bcder::OctetString

source ·
pub struct OctetString(_);
Expand description

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.

Implementations§

Creates an octet string from a Bytes value.

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.

Returns an iterator over the individual octets of the string.

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.

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 contnent. Otherwise it will produce an entirely new bytes value from the concatenated content of all the primitive values.

Returns the length of the content.

This is not the length of the encoded value but of the actual octet string.

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.

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.

Takes an octet string value from content.

Returns a value encoder for the octet string using the natural tag.

Returns a value encoder for the octet string using the given tag.

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.

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.