Rust PRECIS Framework libray
PRECIS Framework: Preparation, Enforcement, and Comparison of Internationalized Strings in Application Protocols as described in rfc8264
This workspace implements the next crates:
precis-tools
This crate contains all the tools and parsers to generate PRECIS tables from the Unicode Character Database (UCD)[https://unicode.org]. This crate is only used to generate code required by precis-core
and precis-profiles
. It contains the main dependencies in order to download UCD files, parse them and generate Rust code.
precis-core
The core library of the PRECIS Framework. The base string classes IdentifierClass
and FreeFormClass
are implemented here as defined in rfc8264. This crate provides the APIs required for profiles to be implemented. You mostly won't require this crate unless you are implementing a new profile.
precis-profiles
This crate implements the next PRECIS profiles:
- rfc8265. Preparation, Enforcement, and Comparison of Internationalized Strings Representing Usernames and Passwords.
- rfc8266. Preparation, Enforcement, and Comparison of Internationalized Strings Representing Nicknames
PRECIS profiles provides an API that allows application to prepare, enforce and compare internacionalized strings.
Example
use precis_core::Error;
use precis_core::profile::Profile;
use precis_profiles::OpaqueString;
use std::borrow::Cow;
// create OpaqueString profile
let profile = OpaqueString::new();
// prepare string
assert_eq!(profile.prepare("I'm Guybrush Threepwood, Mighty Pirate ☠"),
Ok(Cow::from("I'm Guybrush Threepwood, Mighty Pirate ☠")));
// enforce string
assert_eq!(profile.enforce("Look behind you, a three-headed monkey!🐒"),
Ok(Cow::from("Look behind you, a three-headed monkey!🐒")));
// compare strings
assert_eq!(profile.compare("That’s the second biggest 🐵 I’ve ever seen!",
"That’s the second biggest 🐵 I’ve ever seen!"), Ok(true));
If you find yourself continuously creating and destroying profiles to perform any of the operation described for internationalized string. You can make use of the PrecisFastInvocation trait. Profiles implementing this crate will allow you to prepare, enforce or compare string without having to instantiate a specific profile. Profiles usually use a static instance allocated with lazy_static
Example
extern crate precis_profiles;
use precis_core::profile::PrecisFastInvocation;
use precis_profiles::Nickname;
use std::borrow::Cow;
fn main() {
assert_eq!(Nickname::prepare("Guybrush Threepwood"),
Ok(Cow::from("Guybrush Threepwood")));
assert_eq!(Nickname::enforce(" Guybrush Threepwood "),
Ok(Cow::from("Guybrush Threepwood")));
assert_eq!(Nickname::compare("Guybrush Threepwood ",
"guybrush threepwood"), Ok(true));
}
crates.io
You can use this package in your project by adding the following to your Cargo.toml
:
[dependencies]
precis-profiles = "0.1.0"
Known limitations
PRECIS recommends using toLowerCase() operation as defined in the Unicode Standard Unicode. This implementation uses the one provided by Rust standard library to_lowercase. This operation performs an unconditional mapping without tailoring. That is, the conversion is independent of context and language.