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§

source§

impl<L: CharSet> RestrictedString<L>

source

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.

source

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.

source

pub fn chars(&self) -> RestrictedStringChars<'_, L>

Returns an iterator over the character in the character string.

source

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.

source§

impl<L: CharSet> RestrictedString<L>

source

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.

source

pub fn from_content<S: Source>( content: &mut Content<'_, S> ) -> Result<Self, DecodeError<S::Error>>

Takes a character set from content.

source

pub fn encode(self) -> impl Values

Returns a value encoder for the character string with the natural tag.

source

pub fn encode_as(self, tag: Tag) -> impl Values

Returns a value encoder for the character string with the given tag.

source

pub fn encode_ref(&self) -> impl Values + '_

Returns a value encoder for the character string with the natural tag.

source

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>§

source

pub fn iter(&self) -> OctetStringIter<'_>

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.

source

pub fn octets(&self) -> OctetStringOctets<'_>

Returns an iterator over the individual octets of the string.

source

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.

source

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.

source

pub fn len(&self) -> usize

Returns the length of the content.

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

source

pub fn is_empty(&self) -> bool

Returns whether the content is empty.

source

pub fn encode_ref(&self) -> impl Values + '_

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

source

pub fn encode_ref_as(&self, tag: Tag) -> impl Values + '_

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

Trait Implementations§

source§

impl<L: CharSet> AsRef<OctetString> for RestrictedString<L>

source§

fn as_ref(&self) -> &OctetString

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<L: Clone + CharSet> Clone for RestrictedString<L>

source§

fn clone(&self) -> RestrictedString<L>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<L: Debug + CharSet> Debug for RestrictedString<L>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<L: CharSet> Deref for RestrictedString<L>

§

type Target = OctetString

The resulting type after dereferencing.
source§

fn deref(&self) -> &OctetString

Dereferences the value.
source§

impl<L: CharSet> Display for RestrictedString<L>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<L: CharSet> FromStr for RestrictedString<L>

§

type Err = CharSetError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, CharSetError>

Parses a string s to return a value of this type. Read more
source§

impl<L: CharSet> Hash for RestrictedString<L>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, L: CharSet> IntoIterator for &'a RestrictedString<L>

§

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?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<L: CharSet> Ord for RestrictedString<L>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<L: CharSet> PartialEq for RestrictedString<L>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<L: CharSet> PartialOrd for RestrictedString<L>

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.