| Crates.io | x520-stringprep |
| lib.rs | x520-stringprep |
| version | 1.0.0 |
| created_at | 2025-08-02 15:59:34.001614+00 |
| updated_at | 2025-08-02 15:59:34.001614+00 |
| description | String preparation algorithm as described in ITU-T Recommendation X.520 |
| homepage | |
| repository | https://github.com/JonathanWilbur/asn1.rs/tree/master/x690 |
| max_upload_size | |
| id | 1778956 |
| size | 74,622 |
String preparation / normalization per the procedures defined in ITU-T Recommendation X.520 (2019), Section 7. These procedures were defined for usage in X.500 directories, but they may be used elsewhere.
This library is no_std: it does not require the standard library and can be
used in embedded systems.
A basic example, using the most basic building-block of this library:
# extern crate alloc;
# use alloc::string::String;
# use x520_stringprep::{
# x520_stringprep_case_exact_str,
# x520_stringprep_case_ignore_str
# };
let input = " Hello\te\u{0301}\u{2000}Ä\u{FB03}n ";
let output: String = x520_stringprep_case_exact_str(input)
.map(|maybe_c| maybe_c.unwrap())
.collect();
assert_eq!(output, " Hello é Äffin ");
let output: String = x520_stringprep_case_ignore_str(input)
.map(|maybe_c| maybe_c.unwrap())
.collect();
assert_eq!(output, " hello é äffin ");
You might notice that the outputs above are not trimmed, even though this is a requirement in the specification. This is done because this might be a performance-critical operation, so it is left to the caller to trim strings only if it is believed that they need it. Trimming is a pretty trivial step that can be performed prior to storage in a database; once it is done, subsequent retrievals from this database won't need trimming.
Since this library is likely to be used with ASN.1, there are also functions
meant for preparing BMPString and UniversalString:
x520_stringprep_case_exact_bmpx520_stringprep_case_ignore_bmpx520_stringprep_case_exact_univ_strx520_stringprep_case_ignore_univ_strThese functions allow you to check if a string is already prepared:
is_x520_stringprepped_case_exact_stris_x520_stringprepped_case_ignore_strThese allow you to compare strings:
x520_stringprep_case_exact_compare, which can be used in implementations of
caseExactMatch and other such matching rules.x520_stringprep_case_ignore_compare, which can be used in implementations of
caseIgnoreMatch and other such matching rules.If you enable the alloc feature flag, you also get these convenience functions
that return owned strings from the preparation procedure:
x520_stringprep_to_case_exact_stringx520_stringprep_to_case_ignore_stringNone of the library code was produced by an AI or LLM of any kind, but the unit tests were written by the Cursor editor, and LLM-based autocomplete was used in producing documentation comments. The unit tests were individually reviewed by the author.