import "golang.org/x/text/secure/precis"
Package precis contains types and functions for the preparation, enforcement, and comparison of internationalized strings ("PRECIS") as defined in RFC 7564. It also contains several pre-defined profiles for passwords, nicknames, and usernames as defined in RFC 7613 and RFC 7700.
BE ADVISED: This package is under construction and the API may change in backwards incompatible ways and without notice.
class.go doc.go nickname.go options.go profile.go profiles.go tables.go transformer.go trieval.go
const UnicodeVersion = "8.0.0"
UnicodeVersion is the Unicode version from which the tables in this package are derived.
type Option func(*options)
An Option is used to define the behavior and rules of a Profile.
var ( // The IgnoreCase option causes the profile to perform a case insensitive // comparison during the PRECIS comparison step. IgnoreCase Option = ignoreCase // The AllowWide option causes the profile to allow full-width and half-width // characters by mapping them to their decomposition mappings. This is useful // for profiles that are based on the identifier class which would otherwise // disallow wide characters. AllowWide Option = allowWide // The DisallowEmpty option causes the enforcement step to return an error if // the resulting string would be empty. DisallowEmpty Option = disallowEmpty )
func AdditionalMapping(t ...func() transform.Transformer) Option
The AdditionalMapping option defines the additional mapping rule for the Profile by applying Transformer's in sequence.
The Disallow option further restricts a Profile's allowed characters beyond what is disallowed by the underlying string class.
The FoldCase option defines a Profile's case mapping rule. Options can be provided to determine the type of case folding used.
The Norm option defines a Profile's normalization rule. Defaults to NFC.
func Width(w width.Transformer) Option
The Width option defines a Profile's width mapping rule.
type Profile struct { transform.NopResetter // contains filtered or unexported fields }
A Profile represents a set of rules for normalizing and validating strings in the PRECIS framework.
var ( Nickname Profile = nickname // Implements the Nickname profile specified in RFC 7700. UsernameCaseMapped Profile = usernamecasemap // Implements the UsernameCaseMapped profile specified in RFC 7613. UsernameCasePreserved Profile = usernamenocasemap // Implements the UsernameCasePreserved profile specified in RFC 7613. OpaqueString Profile = opaquestring // Implements the OpaqueString profile defined in RFC 7613 for passwords and other secure labels. )
NewFreeform creates a new PRECIS profile based on the Freeform string class. Profiles created from this class are suitable for use where expressiveness is prioritized over safety like passwords, and display-elements such as nicknames in a chat room.
NewIdentifier creates a new PRECIS profile based on the Identifier string class. Profiles created from this class are suitable for use where safety is prioritized over expressiveness like network identifiers, user accounts, chat rooms, and file names.
Allowed returns a runes.Set containing every rune that is a member of the underlying profile's string class and not disallowed by any profile specific rules.
Bytes returns a new byte slice with the result of applying the profile to b.
Compare enforces both strings, and then compares them for bit-string identity (byte-for-byte equality). If either string cannot be enforced, the comparison is false.
func (p Profile) NewTransformer() *Transformer
NewTransformer creates a new transform.Transformer that performs the PRECIS preparation and enforcement steps on the given UTF-8 encoded bytes.
String returns a string with the result of applying the profile to s.
type Transformer struct {
// contains filtered or unexported fields
}
Transformer implements the transform.Transformer interface.
func (t Transformer) Bytes(b []byte) []byte
Bytes returns a new byte slice with the result of applying t to b.
func (t Transformer) Reset()
Reset implements the transform.Transformer interface.
func (t Transformer) String(s string) string
String returns a string with the result of applying t to s.
Transform implements the transform.Transformer interface.
Package precis imports 8 packages (graph) and is imported by 1 packages. Updated about 2 hours ago. Refresh now. Tools for package owners.