OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / secure / precis / profiles.go
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
5 package precis
6
7 import (
8         "unicode"
9
10         "golang.org/x/text/runes"
11         "golang.org/x/text/transform"
12         "golang.org/x/text/unicode/norm"
13 )
14
15 var (
16         // Implements the Nickname profile specified in RFC 7700.
17         // The nickname profile is not idempotent and may need to be applied multiple
18         // times before being used for comparisons.
19         Nickname *Profile = nickname
20
21         // Implements the UsernameCaseMapped profile specified in RFC 7613.
22         UsernameCaseMapped *Profile = usernameCaseMap
23
24         // Implements the UsernameCasePreserved profile specified in RFC 7613.
25         UsernameCasePreserved *Profile = usernameNoCaseMap
26
27         // Implements the OpaqueString profile defined in RFC 7613 for passwords and other secure labels.
28         OpaqueString *Profile = opaquestring
29 )
30
31 var (
32         nickname = &Profile{
33                 options: getOpts(
34                         AdditionalMapping(func() transform.Transformer {
35                                 return &nickAdditionalMapping{}
36                         }),
37                         IgnoreCase,
38                         Norm(norm.NFKC),
39                         DisallowEmpty,
40                 ),
41                 class: freeform,
42         }
43         usernameCaseMap = &Profile{
44                 options: getOpts(
45                         FoldWidth,
46                         LowerCase(),
47                         Norm(norm.NFC),
48                         BidiRule,
49                 ),
50                 class: identifier,
51         }
52         usernameNoCaseMap = &Profile{
53                 options: getOpts(
54                         FoldWidth,
55                         Norm(norm.NFC),
56                         BidiRule,
57                 ),
58                 class: identifier,
59         }
60         opaquestring = &Profile{
61                 options: getOpts(
62                         AdditionalMapping(func() transform.Transformer {
63                                 return mapSpaces
64                         }),
65                         Norm(norm.NFC),
66                         DisallowEmpty,
67                 ),
68                 class: freeform,
69         }
70 )
71
72 // mapSpaces is a shared value of a runes.Map transformer.
73 var mapSpaces transform.Transformer = runes.Map(func(r rune) rune {
74         if unicode.Is(unicode.Zs, r) {
75                 return ' '
76         }
77         return r
78 })