Struct bcder::string::RestrictedString
source · [−]pub struct RestrictedString<L: CharSet> { /* private fields */ }
Expand description
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.
Implementations
sourceimpl<L: CharSet> RestrictedString<L>
impl<L: CharSet> RestrictedString<L>
sourcepub fn new(os: OctetString) -> Result<Self, CharSetError>
pub fn new(os: OctetString) -> Result<Self, CharSetError>
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.
sourcepub fn from_string(s: String) -> Result<Self, CharSetError>
pub fn from_string(s: String) -> Result<Self, CharSetError>
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.
sourcepub fn chars(&self) -> RestrictedStringChars<'_, L>ⓘNotable traits for RestrictedStringChars<'a, L>impl<'a, L: CharSet> Iterator for RestrictedStringChars<'a, L> type Item = char;
pub fn chars(&self) -> RestrictedStringChars<'_, L>ⓘNotable traits for RestrictedStringChars<'a, L>impl<'a, L: CharSet> Iterator for RestrictedStringChars<'a, L> type Item = char;
Returns an iterator over the character in the character string.
sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Converts the string into its underlying bytes.
Note that the bytes value will contain the raw octets of the string which are not necessarily a valid Rust string.
sourceimpl<L: CharSet> RestrictedString<L>
impl<L: CharSet> RestrictedString<L>
sourcepub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
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.
sourcepub fn from_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn from_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<Self, DecodeError<S::Error>>
Takes a character set from content.
sourcepub fn encode(self) -> impl Values
pub fn encode(self) -> impl Values
Returns a value encoder for the character string with the natural tag.
sourcepub fn encode_as(self, tag: Tag) -> impl Values
pub fn encode_as(self, tag: Tag) -> impl Values
Returns a value encoder for the character string with the given tag.
sourcepub fn encode_ref(&self) -> impl Values + '_
pub fn encode_ref(&self) -> impl Values + '_
Returns a value encoder for the character string with the natural tag.
sourcepub fn encode_ref_as(&self, tag: Tag) -> impl Values + '_
pub fn encode_ref_as(&self, tag: Tag) -> impl Values + '_
Returns a value encoder for the character string with the given tag.
Methods from Deref<Target = OctetString>
sourcepub fn iter(&self) -> OctetStringIter<'_>ⓘNotable traits for OctetStringIter<'a>impl<'a> Iterator for OctetStringIter<'a> type Item = &'a [u8];
pub fn iter(&self) -> OctetStringIter<'_>ⓘNotable traits for OctetStringIter<'a>impl<'a> Iterator for OctetStringIter<'a> type Item = &'a [u8];
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.
sourcepub fn octets(&self) -> OctetStringOctets<'_>ⓘNotable traits for OctetStringOctets<'a>impl<'a> Iterator for OctetStringOctets<'a> type Item = u8;
pub fn octets(&self) -> OctetStringOctets<'_>ⓘNotable traits for OctetStringOctets<'a>impl<'a> Iterator for OctetStringOctets<'a> type Item = u8;
Returns an iterator over the individual octets of the string.
sourcepub fn as_slice(&self) -> Option<&[u8]>
pub fn as_slice(&self) -> Option<&[u8]>
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.
sourcepub fn to_bytes(&self) -> Bytes
pub fn to_bytes(&self) -> Bytes
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.
sourcepub fn encode_ref(&self) -> impl Values + '_
pub fn encode_ref(&self) -> impl Values + '_
Returns a value encoder for the octet string using the natural tag.
sourcepub fn encode_ref_as(&self, tag: Tag) -> impl Values + '_
pub fn encode_ref_as(&self, tag: Tag) -> impl Values + '_
Returns a value encoder for the octet string using the given tag.
Trait Implementations
sourceimpl<L: CharSet> AsRef<OctetString> for RestrictedString<L>
impl<L: CharSet> AsRef<OctetString> for RestrictedString<L>
sourcefn as_ref(&self) -> &OctetString
fn as_ref(&self) -> &OctetString
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl<L: Clone + CharSet> Clone for RestrictedString<L>
impl<L: Clone + CharSet> Clone for RestrictedString<L>
sourcefn clone(&self) -> RestrictedString<L>
fn clone(&self) -> RestrictedString<L>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<L: Debug + CharSet> Debug for RestrictedString<L>
impl<L: Debug + CharSet> Debug for RestrictedString<L>
sourceimpl<L: CharSet> Deref for RestrictedString<L>
impl<L: CharSet> Deref for RestrictedString<L>
type Target = OctetString
type Target = OctetString
The resulting type after dereferencing.
sourcefn deref(&self) -> &OctetString
fn deref(&self) -> &OctetString
Dereferences the value.
sourceimpl<L: CharSet> Display for RestrictedString<L>
impl<L: CharSet> Display for RestrictedString<L>
sourceimpl<L: CharSet> FromStr for RestrictedString<L>
impl<L: CharSet> FromStr for RestrictedString<L>
type Err = CharSetError
type Err = CharSetError
The associated error which can be returned from parsing.
sourceimpl<L: CharSet> Hash for RestrictedString<L>
impl<L: CharSet> Hash for RestrictedString<L>
sourceimpl<'a, L: CharSet> IntoIterator for &'a RestrictedString<L>
impl<'a, L: CharSet> IntoIterator for &'a RestrictedString<L>
sourceimpl<L: CharSet> Ord for RestrictedString<L>
impl<L: CharSet> Ord for RestrictedString<L>
sourceimpl<L: CharSet> PartialEq<RestrictedString<L>> for RestrictedString<L>
impl<L: CharSet> PartialEq<RestrictedString<L>> for RestrictedString<L>
sourceimpl<L: CharSet> PartialOrd<RestrictedString<L>> for RestrictedString<L>
impl<L: CharSet> PartialOrd<RestrictedString<L>> for RestrictedString<L>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<L: CharSet> Eq for RestrictedString<L>
Auto Trait Implementations
impl<L> RefUnwindSafe for RestrictedString<L> where
L: RefUnwindSafe,
impl<L> Send for RestrictedString<L> where
L: Send,
impl<L> Sync for RestrictedString<L> where
L: Sync,
impl<L> Unpin for RestrictedString<L> where
L: Unpin,
impl<L> UnwindSafe for RestrictedString<L> where
L: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more