profiles.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package precis
  5. import (
  6. "unicode"
  7. "golang.org/x/text/runes"
  8. "golang.org/x/text/transform"
  9. "golang.org/x/text/unicode/norm"
  10. )
  11. var (
  12. Nickname *Profile = nickname // Implements the Nickname profile specified in RFC 7700.
  13. UsernameCaseMapped *Profile = usernameCaseMap // Implements the UsernameCaseMapped profile specified in RFC 7613.
  14. UsernameCasePreserved *Profile = usernameNoCaseMap // Implements the UsernameCasePreserved profile specified in RFC 7613.
  15. OpaqueString *Profile = opaquestring // Implements the OpaqueString profile defined in RFC 7613 for passwords and other secure labels.
  16. )
  17. // TODO: mvl: "Ultimately, I would manually define the structs for the internal
  18. // profiles. This avoid pulling in unneeded tables when they are not used."
  19. var (
  20. nickname = NewFreeform(
  21. AdditionalMapping(func() transform.Transformer {
  22. return &nickAdditionalMapping{}
  23. }),
  24. IgnoreCase,
  25. Norm(norm.NFKC),
  26. DisallowEmpty,
  27. )
  28. usernameCaseMap = NewIdentifier(
  29. FoldWidth,
  30. FoldCase(),
  31. Norm(norm.NFC),
  32. BidiRule,
  33. )
  34. usernameNoCaseMap = NewIdentifier(
  35. FoldWidth,
  36. Norm(norm.NFC),
  37. BidiRule,
  38. )
  39. opaquestring = NewFreeform(
  40. AdditionalMapping(func() transform.Transformer {
  41. return runes.Map(func(r rune) rune {
  42. if unicode.Is(unicode.Zs, r) {
  43. return ' '
  44. }
  45. return r
  46. })
  47. }),
  48. Norm(norm.NFC),
  49. DisallowEmpty,
  50. )
  51. )