X.520 String Preparation
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.
Example Usage
A basic example, using the most basic building-block of this library:
# extern crate alloc;
# use String;
# use ;
let input = " Hello\te\u{0301}\u{2000}Ä\u{FB03}n ";
let output: String = x520_stringprep_case_exact_str
.map
.collect;
assert_eq!;
let output: String = x520_stringprep_case_ignore_str
.map
.collect;
assert_eq!;
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_bmp
x520_stringprep_case_ignore_bmp
x520_stringprep_case_exact_univ_str
x520_stringprep_case_ignore_univ_str
These functions allow you to check if a string is already prepared:
is_x520_stringprepped_case_exact_str
is_x520_stringprepped_case_ignore_str
These allow you to compare strings:
x520_stringprep_case_exact_compare
, which can be used in implementations ofcaseExactMatch
and other such matching rules.x520_stringprep_case_ignore_compare
, which can be used in implementations ofcaseIgnoreMatch
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_string
x520_stringprep_to_case_ignore_string
AI Usage Statement
None 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.