libidn 1.43

profiles.c
Go to the documentation of this file.
1/* profiles.c --- Definitions of stringprep profiles.
2 Copyright (C) 2002-2025 Simon Josefsson
3
4 This file is part of GNU Libidn.
5
6 GNU Libidn is free software: you can redistribute it and/or
7 modify it under the terms of either:
8
9 * the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 3 of the License, or (at
11 your option) any later version.
12
13 or
14
15 * the GNU General Public License as published by the Free
16 Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
18
19 or both in parallel, as here.
20
21 GNU Libidn is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
25
26 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <https://www.gnu.org/licenses/>. */
29
30#include <config.h>
31#include "stringprep.h"
32#include "rfc3454.h"
33
34 const Stringprep_profiles stringprep_profiles[] = {
35 {"Nameprep", stringprep_nameprep},
36 {"KRBprep", stringprep_kerberos5}, /* Deprecate? */
37 {"Nodeprep", stringprep_xmpp_nodeprep},
38 {"Resourceprep", stringprep_xmpp_resourceprep},
39 {"plain", stringprep_plain}, /* sasl-anon-00. */
40 {"trace", stringprep_trace}, /* sasl-anon-01,02,03. */
41 {"SASLprep", stringprep_saslprep},
42 {"ISCSIprep", stringprep_iscsi}, /* Obsolete. */
43 {"iSCSI", stringprep_iscsi}, /* IANA. */
44 {NULL, NULL}
45};
46
47/* number of elements within an array */
48#define countof(a) (sizeof(a)/sizeof(*(a)))
49
50/* helper for profile definitions */
51#define TABLE(x) stringprep_rfc3454_##x, N_STRINGPREP_rfc3454_##x
52
53 const Stringprep_profile stringprep_nameprep[] = {
54 {STRINGPREP_MAP_TABLE, 0, TABLE (B_1)},
55 {STRINGPREP_MAP_TABLE, 0, TABLE (B_2)},
56 {STRINGPREP_NFKC, 0, 0, 0},
57 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_2)},
58 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
59 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
60 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
61 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
62 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
63 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_7)},
64 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
65 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
66 {STRINGPREP_BIDI, 0, 0, 0},
67 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI, TABLE (C_8)},
68 {STRINGPREP_BIDI_RAL_TABLE, 0, TABLE (D_1)},
69 {STRINGPREP_BIDI_L_TABLE, 0, TABLE (D_2)},
70 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED, TABLE (A_1)},
71 {0}
72};
73
74 const Stringprep_profile stringprep_kerberos5[] = {
75 /* XXX this is likely to be wrong as the specification is
76 a rough draft. */
77 {STRINGPREP_MAP_TABLE, 0, TABLE (B_1)},
78 {STRINGPREP_MAP_TABLE, 0, TABLE (B_3)},
79 {STRINGPREP_NFKC, 0, 0, 0},
80 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_2)},
81 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
82 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
83 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
84 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
85 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
86 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_7)},
87 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
88 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
89 {STRINGPREP_BIDI, 0, 0, 0},
90 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI, TABLE (C_8)},
91 {STRINGPREP_BIDI_RAL_TABLE, 0, TABLE (D_1)},
92 {STRINGPREP_BIDI_L_TABLE, 0, TABLE (D_2)},
93 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED, TABLE (A_1)},
94 {0}
95};
96
97 const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[] = {
98 {0x000022, 0x000022}, /* #x22 (") */
99 {0x000026, 0x000026}, /* #x26 (&) */
100 {0x000027, 0x000027}, /* #x27 (') */
101 {0x00002F, 0x00002F}, /* #x2F (/) */
102 {0x00003A, 0x00003A}, /* #x3A (:) */
103 {0x00003C, 0x00003C}, /* #x3C (<) */
104 {0x00003E, 0x00003E}, /* #x3E (>) */
105 {0x000040, 0x000040}, /* #x40 (@) */
106 {0}
107};
108
109 const Stringprep_profile stringprep_xmpp_nodeprep[] = {
110 {STRINGPREP_MAP_TABLE, 0, TABLE (B_1)},
111 {STRINGPREP_MAP_TABLE, 0, TABLE (B_2)},
112 {STRINGPREP_NFKC, 0, 0, 0},
113 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_1)},
114 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_2)},
115 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_1)},
116 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
117 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
118 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
119 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
120 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
121 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_7)},
122 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
123 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
124 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_xmpp_nodeprep_prohibit,
125 countof (stringprep_xmpp_nodeprep_prohibit) - 1},
126 {STRINGPREP_BIDI, 0, 0, 0},
127 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, TABLE (C_8)},
128 {STRINGPREP_BIDI_RAL_TABLE, 0, TABLE (D_1)},
129 {STRINGPREP_BIDI_L_TABLE, 0, TABLE (D_2)},
130 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED, TABLE (A_1)},
131 {0}
132};
133
134 const Stringprep_profile stringprep_xmpp_resourceprep[] = {
135 {STRINGPREP_MAP_TABLE, 0, TABLE (B_1)},
136 {STRINGPREP_NFKC, 0, 0, 0},
137 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_2)},
138 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_1)},
139 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
140 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
141 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
142 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
143 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
144 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_7)},
145 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
146 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
147 {STRINGPREP_BIDI, 0, 0, 0},
148 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, TABLE (C_8)},
149 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_1)},
150 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_2)},
151 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED, TABLE (A_1)},
152 {0}
153};
154
155 const Stringprep_profile stringprep_plain[] = {
156 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_1)},
157 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
158 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
159 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
160 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
161 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
162 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
163 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
164 {STRINGPREP_BIDI, 0, 0, 0},
165 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, TABLE (C_8)},
166 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_1)},
167 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_2)},
168 {0}
169};
170
171 const Stringprep_profile stringprep_trace[] = {
172 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_1)},
173 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
174 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
175 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
176 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
177 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
178 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
179 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
180 {STRINGPREP_BIDI, 0, 0, 0},
181 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, TABLE (C_8)},
182 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_1)},
183 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_2)},
184 {0}
185};
186
187 const Stringprep_table_element stringprep_iscsi_prohibit[] = {
188 {0x0000, 0x002C}, /* [ASCII CONTROL CHARACTERS and SPACE through ,] */
189 {0x002F, 0x002F}, /* [ASCII /] */
190 {0x003B, 0x0040}, /* [ASCII ; through @] */
191 {0x005B, 0x0060}, /* [ASCII [ through `] */
192 {0x007B, 0x007F}, /* [ASCII { through DEL] */
193 {0x3002, 0x3002}, /* ideographic full stop */
194 {0}
195};
196
197 const Stringprep_profile stringprep_iscsi[] = {
198 {STRINGPREP_MAP_TABLE, 0, TABLE (B_1)},
199 {STRINGPREP_MAP_TABLE, 0, TABLE (B_2)},
200 {STRINGPREP_NFKC, 0, 0, 0},
201 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_1)},
202 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_2)},
203 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_1)},
204 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
205 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
206 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
207 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
208 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
209 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_7)},
210 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
211 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
212 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_iscsi_prohibit,
213 countof (stringprep_iscsi_prohibit) - 1},
214 {STRINGPREP_BIDI, 0, 0, 0},
215 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, TABLE (C_8)},
216 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_1)},
217 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_2)},
218 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED, TABLE (A_1)},
219 {0}
220};
221
222 const Stringprep_table_element stringprep_saslprep_space_map[] = {
223 {0x00A0, 0x00A0, {0x0020}}, /* 00A0; NO-BREAK SPACE */
224 {0x1680, 0x1680, {0x0020}}, /* 1680; OGHAM SPACE MARK */
225 {0x2000, 0x200B, {0x0020}}, /* 2000; EN QUAD */
226 /* 2001; EM QUAD */
227 /* 2002; EN SPACE */
228 /* 2003; EM SPACE */
229 /* 2004; THREE-PER-EM SPACE */
230 /* 2005; FOUR-PER-EM SPACE */
231 /* 2006; SIX-PER-EM SPACE */
232 /* 2007; FIGURE SPACE */
233 /* 2008; PUNCTUATION SPACE */
234 /* 2009; THIN SPACE */
235 /* 200A; HAIR SPACE */
236 /* 200B; ZERO WIDTH SPACE */
237 {0x202F, 0x202F, {0x0020}}, /* 202F; NARROW NO-BREAK SPACE */
238 {0x205F, 0x205F, {0x0020}}, /* 205F; MEDIUM MATHEMATICAL SPACE */
239 {0x3000, 0x3000, {0x0020}}, /* 3000; IDEOGRAPHIC SPACE */
240 {0}
241};
242
243 const Stringprep_profile stringprep_saslprep[] = {
244 {STRINGPREP_MAP_TABLE, 0, stringprep_saslprep_space_map,
245 countof (stringprep_saslprep_space_map) - 1},
246 {STRINGPREP_MAP_TABLE, 0, TABLE (B_1)},
247 {STRINGPREP_NFKC, 0, 0, 0},
248 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_1_2)},
249 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_1)},
250 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_2_2)},
251 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_3)},
252 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_4)},
253 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_5)},
254 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_6)},
255 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_7)},
256 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_8)},
257 {STRINGPREP_PROHIBIT_TABLE, 0, TABLE (C_9)},
258 {STRINGPREP_BIDI, 0, 0, 0},
259 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, TABLE (C_8)},
260 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_1)},
261 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, TABLE (D_2)},
262 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED, TABLE (A_1)},
263 {0}
264};
stringprep_kerberos5
const Stringprep_profile stringprep_kerberos5[]
Definition profiles.c:74
stringprep_plain
const Stringprep_profile stringprep_plain[]
Definition profiles.c:155
countof
#define countof(a)
Definition profiles.c:48
stringprep_xmpp_nodeprep_prohibit
const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[]
Definition profiles.c:97
stringprep_saslprep
const Stringprep_profile stringprep_saslprep[]
Definition profiles.c:243
stringprep_iscsi
const Stringprep_profile stringprep_iscsi[]
Definition profiles.c:197
stringprep_profiles
const Stringprep_profiles stringprep_profiles[]
Definition profiles.c:34
stringprep_xmpp_nodeprep
const Stringprep_profile stringprep_xmpp_nodeprep[]
Definition profiles.c:109
stringprep_trace
const Stringprep_profile stringprep_trace[]
Definition profiles.c:171
stringprep_nameprep
const Stringprep_profile stringprep_nameprep[]
Definition profiles.c:53
TABLE
#define TABLE(x)
Definition profiles.c:51
stringprep_xmpp_resourceprep
const Stringprep_profile stringprep_xmpp_resourceprep[]
Definition profiles.c:134
stringprep_iscsi_prohibit
const Stringprep_table_element stringprep_iscsi_prohibit[]
Definition profiles.c:187
stringprep_saslprep_space_map
const Stringprep_table_element stringprep_saslprep_space_map[]
Definition profiles.c:222
rfc3454.h
stringprep.h
STRINGPREP_BIDI_PROHIBIT_TABLE
@ STRINGPREP_BIDI_PROHIBIT_TABLE
Definition stringprep.h:101
STRINGPREP_BIDI_RAL_TABLE
@ STRINGPREP_BIDI_RAL_TABLE
Definition stringprep.h:102
STRINGPREP_NFKC
@ STRINGPREP_NFKC
Definition stringprep.h:96
STRINGPREP_PROHIBIT_TABLE
@ STRINGPREP_PROHIBIT_TABLE
Definition stringprep.h:100
STRINGPREP_UNASSIGNED_TABLE
@ STRINGPREP_UNASSIGNED_TABLE
Definition stringprep.h:99
STRINGPREP_BIDI
@ STRINGPREP_BIDI
Definition stringprep.h:97
STRINGPREP_MAP_TABLE
@ STRINGPREP_MAP_TABLE
Definition stringprep.h:98
STRINGPREP_BIDI_L_TABLE
@ STRINGPREP_BIDI_L_TABLE
Definition stringprep.h:103
Stringprep_profiles
Definition stringprep.h:170
Stringprep_table_element
Definition stringprep.h:132
Stringprep_table
Definition stringprep.h:149