[−][src]Struct bcder::string::RestrictedString
A generic restricted character string.
Restricted character strings essentially are a sequence of characters from
a specific character set mapped into a sequence of octets. In BER, these
are in fact encoded just like an OctetString
with a different tag.
Consequently, this type is a wrapper around OctetString
that makes
sure that the sequence of octets is correctly encoded for the given
character set.
As usual, you can parse a restricted character string from encoded data
by way of the take_from
and from_content
methods.
Alternatively, you can create a new value from a String
or str
via
the from_string
and from_str
associated functions.
Conversely, a restricted character string can be converted into a string
by way of the to_string
and to_str
methods.
In addition, the restricted character string mirrors the standard
library’s string types by dereffing to OctetString
and using the
octet string’s iterators. In addition, the chars
method provides an
iterator over the characters encoded in the string.
Methods
impl<L: CharSet> RestrictedString<L>
[src]
pub fn new(os: OctetString) -> Result<Self, CharSetError>
[src]
Creates a new character string from an octet string.
If the octet string contains octet sequences that are not valid for the character set, an appropriate error will be returned.
pub fn from_string(s: String) -> Result<Self, CharSetError>
[src]
Creates a new character string from a String
.
If the string’s internal representation is identical to the encoding of restricted character string, the string will be reused and no allocation occurs. Otherwise, a new bytes value is created.
If the string cannot be encoded in the character set, an error is returned.
pub fn to_string(&self) -> String
[src]
Creates a string from the character string.
ⓘImportant traits for RestrictedStringChars<'a, L>pub fn chars(&self) -> RestrictedStringChars<L>
[src]
Returns an iterator over the character in the character string.
impl<L: CharSet> RestrictedString<L>
[src]
pub fn take_from<S: Source>(cons: &mut Constructed<S>) -> Result<Self, S::Err>
[src]
Takes a single character set value from constructed value content.
If there is no next value, if the next value does not have the natural tag appropriate for this character set implementation, or if it does not contain a correctly encoded character string, a malformed error is returned.
pub fn from_content<S: Source>(content: &mut Content<S>) -> Result<Self, S::Err>
[src]
Takes a character set from content.
pub fn encode(
self
) -> impl Values
[src]
self
) -> impl Values
Returns a value encoder for the character string with the natural tag.
pub fn encode_as(
self,
tag: Tag
) -> impl Values
[src]
self,
tag: Tag
) -> impl Values
Returns a value encoder for the character string with the given tag.
pub fn encode_ref<'a>(
&'a self
) -> impl Values + 'a
[src]
&'a self
) -> impl Values + 'a
Returns a value encoder for the character string with the natural tag.
pub fn encode_ref_as<'a>(
&'a self,
tag: Tag
) -> impl Values + 'a
[src]
&'a self,
tag: Tag
) -> impl Values + 'a
Returns a value encoder for the character string with the given tag.
Methods from Deref<Target = OctetString>
ⓘ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 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.
pub fn encode_ref<'a>(
&'a self
) -> impl Values + 'a
[src]
&'a self
) -> impl Values + 'a
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]
&'a self,
tag: Tag
) -> impl Values + 'a
Returns a value encoder for the octet string using the given tag.
Trait Implementations
impl<L: CharSet> PartialEq<RestrictedString<L>> for RestrictedString<L>
[src]
fn eq(&self, other: &Self) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<L: CharSet> AsRef<OctetString> for RestrictedString<L>
[src]
fn as_ref(&self) -> &OctetString
[src]
impl<'a, L: CharSet> IntoIterator for &'a RestrictedString<L>
[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<L: CharSet> Ord for RestrictedString<L>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl<L: Clone + CharSet> Clone for RestrictedString<L>
[src]
fn clone(&self) -> RestrictedString<L>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<L: CharSet> Eq for RestrictedString<L>
[src]
impl<L: CharSet> PartialOrd<RestrictedString<L>> for RestrictedString<L>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<L: CharSet> Deref for RestrictedString<L>
[src]
type Target = OctetString
The resulting type after dereferencing.
fn deref(&self) -> &OctetString
[src]
impl<L: CharSet> Hash for RestrictedString<L>
[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,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<L: Debug + CharSet> Debug for RestrictedString<L>
[src]
impl<L: CharSet> FromStr for RestrictedString<L>
[src]
type Err = CharSetError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, CharSetError>
[src]
Auto Trait Implementations
impl<L> Send for RestrictedString<L> where
L: Send,
L: Send,
impl<L> Sync for RestrictedString<L> where
L: Sync,
L: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,