diff --git a/icu/src/lib.rs b/icu/src/lib.rs index fa058b4..31afb5e 100644 --- a/icu/src/lib.rs +++ b/icu/src/lib.rs @@ -18,7 +18,7 @@ use crate::bindings::{ pub use crate::error::Error; pub use crate::idna2008::Idna; pub use crate::spoof::SpoofChecker; -pub use crate::stringprep::Stringprep; +use crate::stringprep::Stringprep; /// How unassigned codepoints should be handled. pub enum Strict { @@ -31,25 +31,10 @@ pub enum Strict { /// Main struct of this module, exposing the needed ICU functions to JID. pub struct Icu { - /// Perform stringprep using the Nameprep profile. - /// - /// See [RFC3491](https://tools.ietf.org/html/rfc3491). - pub nameprep: Stringprep, - - /// Perform stringprep using the Nodeprep profile. - /// - /// See [RFC6122 appendix A](https://tools.ietf.org/html/rfc6122#appendix-A). - pub nodeprep: Stringprep, - - /// Perform stringprep using the Resourceprep profile. - /// - /// See [RFC6122 appendix A](https://tools.ietf.org/html/rfc6122#appendix-A). - pub resourceprep: Stringprep, - - /// Perform stringprep using the Saslprep profile. - /// - /// See [RFC4013](https://tools.ietf.org/html/rfc4013). - pub saslprep: Stringprep, + nameprep: Stringprep, + nodeprep: Stringprep, + resourceprep: Stringprep, + saslprep: Stringprep, /// IDNA2008 support. /// @@ -86,6 +71,34 @@ impl Icu { spoofchecker, }) } + + /// Perform stringprep using the Nameprep profile. + /// + /// See [RFC3491](https://tools.ietf.org/html/rfc3491). + pub fn nameprep(&self, string: &str, strict: Strict) -> Result { + self.nameprep.stringprep(string, strict) + } + + /// Perform stringprep using the Nodeprep profile. + /// + /// See [RFC6122 appendix A](https://tools.ietf.org/html/rfc6122#appendix-A). + pub fn nodeprep(&self, string: &str, strict: Strict) -> Result { + self.nodeprep.stringprep(string, strict) + } + + /// Perform stringprep using the Resourceprep profile. + /// + /// See [RFC6122 appendix A](https://tools.ietf.org/html/rfc6122#appendix-A). + pub fn resourceprep(&self, string: &str, strict: Strict) -> Result { + self.resourceprep.stringprep(string, strict) + } + + /// Perform stringprep using the Saslprep profile. + /// + /// See [RFC4013](https://tools.ietf.org/html/rfc4013). + pub fn saslprep(&self, string: &str, strict: Strict) -> Result { + self.saslprep.stringprep(string, strict) + } } #[cfg(test)] diff --git a/icu/src/stringprep.rs b/icu/src/stringprep.rs index c4436d7..ee6b150 100644 --- a/icu/src/stringprep.rs +++ b/icu/src/stringprep.rs @@ -11,7 +11,7 @@ use crate::Strict; use std::ptr::null_mut; /// Struct representing a given stringprep profile. -pub struct Stringprep { +pub(crate) struct Stringprep { inner: *mut UStringPrepProfile, } @@ -30,7 +30,7 @@ impl Stringprep { /// /// # Panics /// Panics if ICU doesn’t return a valid UTF-16 string, which should never happen. - pub fn stringprep(&self, input: &str, strict: Strict) -> Result { + pub(crate) fn stringprep(&self, input: &str, strict: Strict) -> Result { if input.len() > 1023 { return Err(Error::TooLong); }