### resourceprep Source: https://context7.com/sfackler/rust-stringprep/llms.txt Prepares a string with the Resourceprep profile (RFC 3920 Appendix B), used for normalizing the resource part of a XMPP JID. ```APIDOC ## resourceprep ### Description Prepares a string with the Resourceprep profile (RFC 3920 Appendix B). This is used to normalize the resource part of a XMPP JID (e.g. `user@host/resource`). Unlike Nodeprep, it permits ASCII spaces and the special JID characters (`@`, `/`, etc.). It still strips characters mapped-to-nothing, applies NFKC normalization, and enforces prohibited-character and bidirectional rules. ### Usage ```rust use stringprep::resourceprep; use std::borrow::Cow; let resource = resourceprep("Home Laptop").unwrap(); // resource will be Cow::Borrowed("Home Laptop") let normalized_resource = resourceprep("A").unwrap(); // normalized_resource will be Cow::Borrowed("A") let result = resourceprep("\u{00A0}"); // This will return an error ``` ### Parameters * `input` (string): The string to prepare. ### Returns * `Result, Error>`: The prepared string on success, or an error if the input is invalid. Returns `Cow::Borrowed` for ASCII inputs and `Cow::Owned` for non-ASCII inputs that required normalization. ``` -------------------------------- ### `nameprep` Profile Usage Source: https://context7.com/sfackler/rust-stringprep/llms.txt Illustrates the `nameprep` function for internationalized domain names (IDNs), covering ASCII fast path, case folding, normalization, character mapping, and error conditions for prohibited characters and bidi rules. ```rust use stringprep::nameprep; fn main() { // ASCII fast path for lowercase labels assert_eq!(nameprep("example.com").unwrap(), "example.com"); // Case folding: ASCII uppercase → lowercase assert_eq!(nameprep("CAFE").unwrap(), "cafe"); // German sharp-s: ß → "ss" assert_eq!(nameprep("\u{00DF}").unwrap(), "ss"); // Turkish İ (U+0130) → "i" + combining dot assert_eq!(nameprep("\u{0130}").unwrap(), "\u{0069}\u{0307}"); // Normalization: j + combining caron + NBSP + feminine ordinal assert_eq!(nameprep("j\u{030C}\u{00A0}\u{00AA}").unwrap(), "\u{01F0} a"); // Multiscript internationalized labels assert_eq!( nameprep("安室奈美恵-with-SUPER-MONKEYS").unwrap(), "安室奈美恵-with-super-monkeys" ); assert_eq!(nameprep("Ελληνικά").unwrap(), "ελληνικά"); assert_eq!( nameprep("TạisaohọkhôngthểchỉnóitiếngViệt").unwrap(), "tạisaohọkhôngthểchỉnóitiếngviệt" ); // Characters mapped to nothing (soft hyphen, variation selectors, etc.) let messy = "foo\u{00AD}\u{034F}\u{1806}\u{180B}bar\u{200B}\u{2060}baz\u{FE00}\u{FEFF}"; assert_eq!(nameprep(messy).unwrap(), "foobarbaz"); // Prohibited: non-ASCII control character (U+0085) assert!(nameprep("\u{0085}").is_err()); // Prohibited: ideographic description character assert!(nameprep("\u{2FF5}").is_err()); // Bidi: LCat mixed with RandALCat assert!(nameprep("foo\u{05BE}bar").is_err()); } ``` -------------------------------- ### Resourceprep String Preparation (RFC 3920 Appendix B) Source: https://context7.com/sfackler/rust-stringprep/llms.txt Use resourceprep to normalize the resource part of a XMPP JID. It permits ASCII spaces and special JID characters, strips characters mapped-to-nothing, applies NFKC normalization, and enforces prohibited-character and bidirectional rules. ```rust use stringprep::resourceprep; use std::borrow::Cow; fn main() { // ASCII fast path (full printable ASCII allowed) let result = resourceprep("Home Laptop").unwrap(); assert!(matches!(result, Cow::Borrowed(_))); assert_eq!(result, "Home Laptop"); // @ and / are permitted in resource identifiers assert_eq!(resourceprep("foo@bar").unwrap(), "foo@bar"); assert_eq!(resourceprep("a/b").unwrap(), "a/b"); // Prohibited: non-ASCII space (NBSP) assert!(resourceprep("\u{00A0}").is_err()); // Prohibited: private use area character assert!(resourceprep("\u{E001}").is_err()); // NFKC normalization applied for non-ASCII input // (e.g. fullwidth characters normalized to ASCII equivalents) assert_eq!(resourceprep("A").unwrap(), "A"); // U+FF21 → "A" } ``` -------------------------------- ### x520prep Source: https://context7.com/sfackler/rust-stringprep/llms.txt Prepares a string per ITU-T X.520 Section 7, used for LDAP attribute value preparation. ```APIDOC ## x520prep ### Description Prepares a string per ITU-T X.520 Section 7. This is used for LDAP attribute value preparation. It strips insignificant characters (variation selectors, soft hyphens, zero-width spaces), maps whitespace-like characters to regular space, optionally case-folds for matching rules, and rejects strings starting with a combining character, empty strings, or strings containing private-use/non-character/unassigned code points. It does not apply RFC 3454 bidirectional restrictions. ### Usage ```rust use stringprep::x520prep; // Without case folding let prepared_string = x520prep("J. \tW. \v wuz hĕre", false).unwrap(); // prepared_string will be "J. W. wuz hĕre" // With case folding let folded_string = x520prep("UPPERCASED", true).unwrap(); // folded_string will be "uppercased" let result = x520prep("", false); // This will return an error ``` ### Parameters * `input` (string): The string to prepare. * `case_fold` (boolean): Whether to apply case folding. ### Returns * `Result`: The prepared string on success, or an error if the input is invalid. ``` -------------------------------- ### Nodeprep String Preparation (RFC 3920 Appendix A) Source: https://context7.com/sfackler/rust-stringprep/llms.txt Use nodeprep to normalize the local part of a JID. It extends Nameprep by prohibiting ASCII space and additional symbol characters, and applies case folding. The ASCII fast path accepts printable ASCII minus prohibited characters. ```rust use stringprep::nodeprep; fn main() { // ASCII fast path for simple node names assert_eq!(nodeprep("romeo").unwrap(), "romeo"); // Case folding applied assert_eq!(nodeprep("Romeo").unwrap(), "romeo"); // Internationalized node part (ß → "ss" via case-folding + NFKC) assert_eq!( nodeprep("räksmörgås.josefßon.org").unwrap(), "räksmörgås.josefsson.org" ); // Prohibited: ASCII space assert!(nodeprep(" ").is_err()); // Prohibited: non-ASCII space (NBSP) assert!(nodeprep("\u{00A0}").is_err()); // Prohibited: @ character (forbidden in node part of JID) assert!(nodeprep("foo@bar").is_err()); // Prohibited: other special JID characters assert!(nodeprep("a/b").is_err()); assert!(nodeprep("a:b").is_err()); assert!(nodeprep("a\"b").is_err()); } ``` -------------------------------- ### nodeprep Source: https://context7.com/sfackler/rust-stringprep/llms.txt Prepares a string with the Nodeprep profile (RFC 3920 Appendix A), used for normalizing the local part of a Jabber/XMPP ID (JID). ```APIDOC ## nodeprep ### Description Prepares a string with the Nodeprep profile (RFC 3920 Appendix A). This is used to normalize the local part (node) of a Jabber/XMPP ID (JID). It extends Nameprep by prohibiting ASCII space and additional symbol characters (`"`, `&`, `'`, `/`, `:`, `<`, `>`, `@`), and applies case folding. The ASCII fast path accepts the printable ASCII range minus the above prohibited characters. ### Usage ```rust use stringprep::nodeprep; let normalized_node = nodeprep("Romeo").unwrap(); // normalized_node will be "romeo" let result = nodeprep(" "); // This will return an error ``` ### Parameters * `input` (string): The string to prepare. ### Returns * `Result`: The prepared string on success, or an error if the input is invalid. ``` -------------------------------- ### nameprep Source: https://context7.com/sfackler/rust-stringprep/llms.txt Prepares a string using the Nameprep profile (RFC 3491), primarily for normalizing internationalized domain name (IDN) labels. It performs case folding via NFKC, removes characters mapped to nothing, applies NFKC normalization, and enforces prohibited character and bidirectional rules, supporting a wide range of scripts. ```APIDOC ## nameprep — Prepare a string with the Nameprep profile (RFC 3491) ### Description Used to normalize internationalized domain name (IDN) labels. Case-folds via NFKC (RFC 3454 table B.2), removes characters mapped-to-nothing, applies NFKC normalization, then enforces prohibited character and bidirectional rules. Handles a wide range of scripts including CJK, Arabic, Hebrew, Cyrillic, and more. ### Usage ```rust use stringprep::nameprep; fn main() { // ASCII fast path for lowercase labels assert_eq!(nameprep("example.com").unwrap(), "example.com"); // Case folding: ASCII uppercase → lowercase assert_eq!(nameprep("CAFE").unwrap(), "cafe"); // German sharp-s: ß → "ss" assert_eq!(nameprep("\u{00DF}").unwrap(), "ss"); // Turkish İ (U+0130) → "i" + combining dot assert_eq!(nameprep("\u{0130}").unwrap(), "\u{0069}\u{0307}"); // Normalization: j + combining caron + NBSP + feminine ordinal assert_eq!(nameprep("j\u{030C}\u{00A0}\u{00AA}").unwrap(), "\u{01F0} a"); // Multiscript internationalized labels assert_eq!( nameprep("安室奈美恵-with-SUPER-MONKEYS").unwrap(), "安室奈美恵-with-super-monkeys" ); assert_eq!(nameprep("Ελληνικά").unwrap(), "ελληνικά"); assert_eq!( nameprep("TạisaohọkhôngthểchỉnóitiếngViệt").unwrap(), "tạisaohọkhôngthểchỉnóitiếngviệt" ); // Characters mapped to nothing (soft hyphen, variation selectors, etc.) let messy = "foo\u{00AD}\u{034F}\u{1806}\u{180B}bar\u{200B}\u{2060}baz\u{FE00}\u{FEFF}"; assert_eq!(nameprep(messy).unwrap(), "foobarbaz"); // Prohibited: non-ASCII control character (U+0085) assert!(nameprep("\u{0085}").is_err()); // Prohibited: ideographic description character assert!(nameprep("\u{2FF5}").is_err()); // Bidi: LCat mixed with RandALCat assert!(nameprep("foo\u{05BE}bar").is_err()); } ``` ``` -------------------------------- ### X.520prep String Preparation (ITU-T X.520 Section 7) Source: https://context7.com/sfackler/rust-stringprep/llms.txt Use x520prep for LDAP attribute value preparation. It strips insignificant characters, maps whitespace to space, optionally case-folds, and rejects specific invalid strings. It does not apply RFC 3454 bidirectional restrictions. ```rust use stringprep::x520prep; fn main() { // Simple ASCII, no case fold assert_eq!(x520prep("foo@bar", false).unwrap(), "foo@bar"); // Case folding: uppercase → lowercase assert_eq!(x520prep("UPPERCASED", true).unwrap(), "uppercased"); // Variation selector (U+FE00), tab (U+0009), vertical tab (U+000B) handling: // FE00 stripped; tab/vtab mapped to space assert_eq!( x520prep("J.\u{FE00} \u{09}W. \u{0B}wuz h\u{0115}re", false).unwrap(), "J. W. wuz h\u{0115}re" ); // With case fold: same but also lowercased assert_eq!( x520prep("J.\u{FE00} \u{09}W. \u{0B}wuz h\u{0115}re", true).unwrap(), "j. w. wuz h\u{0115}re" ); // Error: empty string assert!(x520prep("", false).is_err()); // Error: starts with combining character (U+0306 combining breve) assert!(x520prep("\u{0306}hello", true).is_err()); // Error: private use character assert!(x520prep("a\u{E000}b", false).is_err()); // Error display match x520prep("\u{0306}start", false) { Err(e) => println!("Error: {}", e), // "Error: starts with combining character" Ok(s) => println!("OK: {}", s), } } ``` -------------------------------- ### Character Predicates from `tables` Module Source: https://context7.com/sfackler/rust-stringprep/llms.txt Demonstrates the usage of various character classification functions from the `stringprep::tables` module. These functions are useful for custom stringprep profiles or fine-grained character validation. ```rust use stringprep::tables; fn main() { // B.1: Commonly mapped to nothing (soft hyphen, variation selectors, BOM, etc.) assert!(tables::commonly_mapped_to_nothing('\u{00AD}')); // soft hyphen assert!(tables::commonly_mapped_to_nothing('\u{FE0F}')); // variation selector-16 assert!(!tables::commonly_mapped_to_nothing('a')); // B.2: Case folding iterator for NFKC let folded: String = tables::case_fold_for_nfkc('A').collect(); assert_eq!(folded, "a"); let folded_sharp_s: String = tables::case_fold_for_nfkc('\u{00DF}').collect(); assert_eq!(folded_sharp_s, "ss"); // C.1.1 / C.1.2: Space characters assert!(tables::ascii_space_character(' ')); assert!(tables::non_ascii_space_character('\u{00A0}')); // NBSP assert!(tables::non_ascii_space_character('\u{3000}')); // ideographic space // C.2.1 / C.2.2: Control characters assert!(tables::ascii_control_character('\u{0000}')); assert!(tables::ascii_control_character('\u{007F}')); assert!(tables::non_ascii_control_character('\u{0085}')); assert!(tables::non_ascii_control_character('\u{200C}')); // C.3: Private use assert!(tables::private_use('\u{E000}')); assert!(tables::private_use('\u{F0001}')); // C.4: Non-character code points assert!(tables::non_character_code_point('\u{FDD0}')); assert!(tables::non_character_code_point('\u{FFFF}')); // C.6: Inappropriate for plain text assert!(tables::inappropriate_for_plain_text('\u{FFFD}')); // C.7: Inappropriate for canonical representation assert!(tables::inappropriate_for_canonical_representation('\u{2FF5}')); // C.8: Change display properties or deprecated assert!(tables::change_display_properties_or_deprecated('\u{200E}')); // C.9: Tagging characters assert!(tables::tagging_character('\u{E0001}')); // D.1 / D.2: Bidi character classes assert!(tables::bidi_r_or_al('\u{05BE}')); // Hebrew punctuation MAQAF assert!(tables::bidi_l('a')); // A.1: Unassigned code points in Unicode 3.2 assert!(tables::unassigned_code_point('\u{0221}')); // X.520 mappings assert!(tables::x520_mapped_to_nothing('\u{00AD}')); // soft hyphen assert!(tables::x520_mapped_to_space('\u{09}')); // tab → space assert!(tables::x520_mapped_to_space('\u{0A}')); // newline → space } ``` -------------------------------- ### `saslprep` Profile Usage Source: https://context7.com/sfackler/rust-stringprep/llms.txt Demonstrates the `saslprep` function for SASL authentication, including ASCII fast path, case preservation, character stripping, mapping, normalization, and error handling for prohibited characters and bidi violations. ```rust use stringprep::saslprep; use std::borrow::Cow; fn main() { // ASCII fast path — no allocation let result = saslprep("user").unwrap(); assert!(matches!(result, Cow::Borrowed(_))); assert_eq!(result, "user"); // Case is preserved for passwords assert_eq!(saslprep("Secret123").unwrap(), "Secret123"); // Soft hyphen (U+00AD) is stripped assert_eq!(saslprep("I\u{00AD}X").unwrap(), "IX"); // Non-ASCII spaces (e.g. NBSP U+00A0) are mapped to regular space assert_eq!(saslprep("a\u{00A0}b").unwrap(), "a b"); // NFKC normalization: feminine ordinal indicator → "a" assert_eq!(saslprep("\u{00AA}").unwrap(), "a"); // Roman numeral Ⅸ (U+2168) → "IX" assert_eq!(saslprep("\u{2168}").unwrap(), "IX"); // Prohibited: ASCII control character (DEL) assert!(saslprep("pass\u{007F}word").is_err()); // Prohibited: private use character assert!(saslprep("a\u{E000}b").is_err()); // Bidirectional violation: RandALCat without matching end assert!(saslprep("\u{0627}\u{0031}").is_err()); // Valid bidi: RandALCat at both ends assert_eq!( saslprep("\u{0627}\u{0031}\u{0628}").unwrap(), "\u{0627}\u{0031}\u{0628}" ); // Error display match saslprep("bad\u{0007}") { Err(e) => println!("Error: {}", e), // "Error: prohibited character `\u{7}`" Ok(s) => println!("OK: {}", s), } } ``` -------------------------------- ### Stringprep Profile Error Handling Source: https://context7.com/sfackler/rust-stringprep/llms.txt Illustrates how to handle errors returned by stringprep profile functions, which return `Result, Error>`. The `Error` type provides human-readable messages for issues like prohibited characters or bidirectional violations. ```rust use stringprep::{saslprep, nameprep, nodeprep, resourceprep, x520prep}; fn prepare_sasl_password(password: &str) -> Result> { let prepared = saslprep(password)?; Ok(prepared.into_owned()) } fn main() { // Successful preparation match prepare_sasl_password("Pässwörd") { Ok(p) => println!("Prepared password: {}", p), Err(e) => eprintln!("Invalid password: {}", e), } // Prohibited character match saslprep("pass\u{0007}word") { Err(e) => println!("{}", e), // "prohibited character `\u{7}`" Ok(_) => {} } // Bidirectional violation match nameprep("foo\u{05BE}bar") { Err(e) => println!("{}", e), // "prohibited bidirectional text" Ok(_) => {} } // X.520 combining character at start match x520prep("\u{0306}hello", false) { Err(e) => println!("{}", e), // "starts with combining character" Ok(_) => {} } // X.520 empty string match x520prep("", false) { Err(e) => println!("{}", e), // "empty string" Ok(_) => {} } } ``` -------------------------------- ### saslprep Source: https://context7.com/sfackler/rust-stringprep/llms.txt Prepares a string using the SASLprep profile (RFC 4013), suitable for normalizing passwords and usernames in SASL authentication. It handles ASCII fast paths, case preservation for passwords, stripping of soft hyphens, mapping of non-ASCII spaces, NFKC normalization, and rejection of prohibited characters and invalid bidirectional sequences. ```APIDOC ## saslprep — Prepare a string with the SASLprep profile (RFC 4013) ### Description Used to normalize passwords and usernames in SASL authentication. Maps non-ASCII spaces to ASCII space, removes characters mapped-to-nothing (soft hyphens, variation selectors, etc.), applies NFKC normalization, then rejects prohibited characters and invalid bidirectional sequences. Provides an ASCII fast path that returns the original slice without allocation. ### Usage ```rust use stringprep::saslprep; use std::borrow::Cow; fn main() { // ASCII fast path — no allocation let result = saslprep("user").unwrap(); assert!(matches!(result, Cow::Borrowed(_))); assert_eq!(result, "user"); // Case is preserved for passwords assert_eq!(saslprep("Secret123").unwrap(), "Secret123"); // Soft hyphen (U+00AD) is stripped assert_eq!(saslprep("I\u{00AD}X").unwrap(), "IX"); // Non-ASCII spaces (e.g. NBSP U+00A0) are mapped to regular space assert_eq!(saslprep("a\u{00A0}b").unwrap(), "a b"); // NFKC normalization: feminine ordinal indicator → "a" assert_eq!(saslprep("\u{00AA}").unwrap(), "a"); // Roman numeral Ⅸ (U+2168) → "IX" assert_eq!(saslprep("\u{2168}").unwrap(), "IX"); // Prohibited: ASCII control character (DEL) assert!(saslprep("pass\u{007F}word").is_err()); // Prohibited: private use character assert!(saslprep("a\u{E000}b").is_err()); // Bidirectional violation: RandALCat without matching end assert!(saslprep("\u{0627}\u{0031}").is_err()); // Valid bidi: RandALCat at both ends assert_eq!( saslprep("\u{0627}\u{0031}\u{0628}").unwrap(), "\u{0627}\u{0031}\u{0628}" ); // Error display match saslprep("bad\u{0007}") { Err(e) => println!("Error: {}", e), // "Error: prohibited character `\u{7}`" Ok(s) => println!("OK: {}", s), } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.