1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
238
  
239
  
240
  
241
  
242
  
243
  
244
  
245
  
246
  
247
  
248
  
249
  
250
  
251
  
252
  
253
  
254
  
255
  
256
  
257
  
258
  
259
  
260
  
261
  
262
  
263
  
START_MARKER 
 
// - Standards.ISO639_2 
test_equal(Standards.ISO639_2.get_language("swe"),"Swedish") 
test_equal(Standards.ISO639_2.get_language("xxx"),0) 
test_true(sizeof(Standards.ISO639_2.list_languages())>400) 
test_equal(Standards.ISO639_2.map_639_1("sv"),"swe") 
test_equal(Standards.ISO639_2.map_639_1("xx"),0) 
test_true(sizeof(Standards.ISO639_2.list_639_1())>150) 
test_do( 
class A { 
  inherit Standards.ISO639_2; 
  void create() { 
    foreach(indices(b_to_t), string symbol) 
      if(languages[symbol]) error("Overlap in symbol %s\n", symbol); 
  } 
}(); ) 
     
 
// - Standards.PEM 
test_any_equal([[ 
string pem = #"-----BEGIN PRIVACY-ENHANCED MESSAGE----- 
Proc-Type: 4,ENCRYPTED 
Content-Domain: RFC822 
DEK-Info: DES-CBC,F8143EDE5960C597 
Originator-ID-Symmetric: linn@zendia.enet.dec.com,, 
Recipient-ID-Symmetric: linn@zendia.enet.dec.com,ptf-kmc,3 
Key-Info: DES-ECB,RSA-MD2,9FD3AAD2F2691B9A, 
          B70665BB9BF7CBCDA60195DB94F727D3 
Recipient-ID-Symmetric: pem-dev@tis.com,ptf-kmc,4 
Key-Info: DES-ECB,RSA-MD2,161A3F75DC82EF26, 
          E2EF532C65CBCFF79F83A2658132DB47 
 
LLrHB0eJzyhP+/fSStdW8okeEnv47jxe7SJ/iN72ohNcUk2jHEUSoH1nvNSIWL9M 
8tEjmF/zxB+bATMtPjCUWbz8Lr9wloXIkjHUlBLpvXR0UrUzYbkNpk0agV2IzUpk 
J6UiRRGcDSvzrsoK+oNvqu6z7Xs5Xfz5rDqUcMlK1Z6720dcBWGGsDLpTpSCnpot 
dXd/H5LMDWnonNvPCwQUHt== 
-----END PRIVACY-ENHANCED MESSAGE-----"; 
object o = Standards.PEM.Message(pem); 
return o->headers + ([ "pre" : o->pre, "post" : o->post, "body" : o->body ]); 
]],[[ ([ /* 9 elements */ 
  "body": ",\272\307\aG\211\317(O\373\367\322J\327V\362\211\36\22{\370\356<^\355\"\177\210\336\366\242\23\\RM\243\34E\22\240}g\274\324\210X\277L\362\321#\230_\363\304\37\233\1""3->0\224Y\274\374.\277p\226\205\310\222""1\324\224\22\351\275ttR\265""3a\271\r\246M\32\201]\210\315Jd'\245\"E\21\234\r+\363\256\312\n" 
    "\372\203o\252\356\263\355{9]\374\371\254:\224p\311J\325\236\273\333G\\\5a\206\260""2\351N\224\202\236\232-uw\177\37\222\314\ri\350\234\333\317\v\4\24\36", 
  "content-domain": "RFC822", 
  "dek-info": "DES-CBC,F8143EDE5960C597", 
  "key-info": "DES-ECB,RSA-MD2,9FD3AAD2F2691B9A,          B70665BB9BF7CBCDA60195DB94F727D3\0DES-ECB,RSA-MD2,161A3F75DC82EF26,          E2EF532C65CBCFF79F83A2658132DB47", 
  "originator-id-symmetric": "linn@zendia.enet.dec.com,,", 
  "post": "PRIVACY-ENHANCED MESSAGE", 
  "pre": "PRIVACY-ENHANCED MESSAGE", 
  "proc-type": "4,ENCRYPTED", 
  "recipient-id-symmetric": "linn@zendia.enet.dec.com,ptf-kmc,3\0pem-dev@tis.com,ptf-kmc,4" 
]) ]]) 
 
 
// - Standards.URI 
test_equal((string)Standards.URI("g:h",           "http://a/b/c/d;p?q"), "g:h") 
test_equal((string)Standards.URI("g",             "http://a/b/c/d;p?q"), "http://a/b/c/g") 
test_equal((string)Standards.URI("./g",           "http://a/b/c/d;p?q"), "http://a/b/c/g") 
test_equal((string)Standards.URI("g/",            "http://a/b/c/d;p?q"), "http://a/b/c/g/") 
test_equal((string)Standards.URI("/g",            "http://a/b/c/d;p?q"), "http://a/g") 
test_equal((string)Standards.URI("//g",           "http://a/b/c/d;p?q"), "http://g") 
test_equal((string)Standards.URI("?y",            "http://a/b/c/d;p?q"), "http://a/b/c/d;p?y") 
test_equal((string)Standards.URI("g?y",           "http://a/b/c/d;p?q"), "http://a/b/c/g?y") 
test_equal((string)Standards.URI("#s",            "http://a/b/c/d;p?q"), "http://a/b/c/d;p?q#s") 
test_equal((string)Standards.URI("g#s",           "http://a/b/c/d;p?q"), "http://a/b/c/g#s") 
test_equal((string)Standards.URI("g?y#s",         "http://a/b/c/d;p?q"), "http://a/b/c/g?y#s") 
test_equal((string)Standards.URI(";x",            "http://a/b/c/d;p?q"), "http://a/b/c/;x") 
test_equal((string)Standards.URI("g;x",           "http://a/b/c/d;p?q"), "http://a/b/c/g;x") 
test_equal((string)Standards.URI("g;x?y#s",       "http://a/b/c/d;p?q"), "http://a/b/c/g;x?y#s") 
test_equal((string)Standards.URI(".",             "http://a/b/c/d;p?q"), "http://a/b/c/") 
test_equal((string)Standards.URI("./",            "http://a/b/c/d;p?q"), "http://a/b/c/") 
test_equal((string)Standards.URI("..",            "http://a/b/c/d;p?q"), "http://a/b/") 
test_equal((string)Standards.URI("../",           "http://a/b/c/d;p?q"), "http://a/b/") 
test_equal((string)Standards.URI("../g",          "http://a/b/c/d;p?q"), "http://a/b/g") 
test_equal((string)Standards.URI("../..",         "http://a/b/c/d;p?q"), "http://a/") 
test_equal((string)Standards.URI("../../",        "http://a/b/c/d;p?q"), "http://a/") 
test_equal((string)Standards.URI("../../g",       "http://a/b/c/d;p?q"), "http://a/g") 
test_equal((string)Standards.URI("",              "http://a/b/c/d;p?q"), "http://a/b/c/d;p?q") 
test_equal((string)Standards.URI("../../../g",    "http://a/b/c/d;p?q"), "http://a/g") 
test_equal((string)Standards.URI("../../../../g", "http://a/b/c/d;p?q"), "http://a/g") 
test_equal((string)Standards.URI("/./g",          "http://a/b/c/d;p?q"), "http://a/./g") 
test_equal((string)Standards.URI("/../g",         "http://a/b/c/d;p?q"), "http://a/../g") 
test_equal((string)Standards.URI("g.",            "http://a/b/c/d;p?q"), "http://a/b/c/g.") 
test_equal((string)Standards.URI(".g",            "http://a/b/c/d;p?q"), "http://a/b/c/.g") 
test_equal((string)Standards.URI("g..",           "http://a/b/c/d;p?q"), "http://a/b/c/g..") 
test_equal((string)Standards.URI("..g",           "http://a/b/c/d;p?q"), "http://a/b/c/..g") 
test_equal((string)Standards.URI("./../g",        "http://a/b/c/d;p?q"), "http://a/b/g") 
test_equal((string)Standards.URI("./g/.",         "http://a/b/c/d;p?q"), "http://a/b/c/g/") 
test_equal((string)Standards.URI("g/./h",         "http://a/b/c/d;p?q"), "http://a/b/c/g/h") 
test_equal((string)Standards.URI("g/../h",        "http://a/b/c/d;p?q"), "http://a/b/c/h") 
test_equal((string)Standards.URI("g;x=1/./y",     "http://a/b/c/d;p?q"), "http://a/b/c/g;x=1/y") 
test_equal((string)Standards.URI("g;x=1/../y",    "http://a/b/c/d;p?q"), "http://a/b/c/y") 
test_equal((string)Standards.URI("g?y/./x",       "http://a/b/c/d;p?q"), "http://a/b/c/g?y/./x") 
test_equal((string)Standards.URI("g?y/../x",      "http://a/b/c/d;p?q"), "http://a/b/c/g?y/../x") 
test_equal((string)Standards.URI("g#s/./x",       "http://a/b/c/d;p?q"), "http://a/b/c/g#s/./x") 
test_equal((string)Standards.URI("g#s/../x",      "http://a/b/c/d;p?q"), "http://a/b/c/g#s/../x") 
test_equal((string)Standards.URI("http:g",        "http://a/b/c/d;p?q"), "http:g") 
test_equal(Standards.URI("http://www.com/")->get_query_variables(),([])) 
test_equal(Standards.URI("http://www.com/?a=b")->get_query_variables(),(["a":"b"])) 
test_equal(Standards.URI("http://www.com/?a=b&a=b")->get_query_variables(),(["a":"b"])) 
test_equal(Standards.URI("http://www.com/?a=b&c")->get_query_variables(),(["a":"b","c":0])) 
test_equal(Standards.URI("http://www.com/?foo")->get_http_path_query(),"/?foo") 
test_equal(Standards.URI("http://www.com/?")->get_http_path_query(),"/?") 
test_equal(Standards.URI("http://www.com/")->get_http_path_query(),"/") 
test_eval_error(Standards.URI("www.com")) 
test_eq((string)Standards.URI("www.com","http://"),"http://www.com") 
test_eq((string)Standards.URI("ftp://www.com/x?a=b#y","http://"),"ftp://www.com/x?a=b#y") 
// Some tests of empty path followed by a query. 
test_eq(Standards.URI("http://user:??@host?query")->query, "query") 
test_eq(Standards.URI("http://user:??@host?query")->password, "??") 
test_eq(Standards.URI("http://user:??@host?query")->path, "") 
test_eq(Standards.URI("HTTP://WWW.COM/")->scheme, "http") 
// test `== 
test_true(Standards.URI("a://b:c@d:1/e?f=g&h")== 
          Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_true(Standards.URI("A://b:c@D:01/e?f=g&h")== 
          Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_false(Standards.URI("x://b:c@d:1/e?f=g&h")== 
           Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_false(Standards.URI("a://x:c@d:1/e?f=g&h")== 
           Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_false(Standards.URI("a://b:x@d:1/e?f=g&h")== 
           Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_false(Standards.URI("a://b:c@x:1/e?f=g&h")== 
           Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_false(Standards.URI("a://b:c@d:2/e?f=g&h")== 
           Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_false(Standards.URI("a://b:c@d:1/x?f=g&h")== 
           Standards.URI("a://b:c@d:1/e?f=g&h")) 
test_false(Standards.URI("a://b:c@d:1/e?x=g&h")== 
           Standards.URI("a://b:c@d:1/e?f=g&h")) 
// codec 
test_true(decode_value(encode_value(Standards.URI("a://b:c@d:1/e?f=g&h")))== 
          Standards.URI("a://b:c@d:1/e?f=g&h")) 
 
 
test_eval_error(Standards.URI("")) 
test_eval_error(Standards.URI("#foo")) 
test_eval_error(Standards.URI("/foo")) 
test_eval_error(Standards.URI("x_x:")) 
 
 
// - Standards.IDNA 
define([[test_punycode]], [[ 
  test_eq([[Standards.IDNA.Punycode.encode($1)]], [[$2]]) 
  test_eq([[Standards.IDNA.Punycode.decode($2)]], [[$1]]) 
]]) 
test_punycode([["\x644\x64A\x647\x645\x627\x628\x62A\x643\x644" 
                "\x645\x648\x634\x639\x631\x628\x64A\x61F"]], 
              [["egbpdaj6bu4bxfgehfvwxn"]]) // A 
test_punycode([["\x4ED6\x4EEC\x4E3A\x4EC0\x4E48\x4E0D\x8BF4\x4E2D\x6587"]], 
              [["ihqwcrb4cv8a8dqg056pqjye"]]) // B 
test_punycode([["\x4ED6\x5011\x7232\x4EC0\x9EBD\x4E0D\x8AAA\x4E2D\x6587"]], 
              [["ihqwctvzc91f659drss3x8bo0yb"]]) // C 
test_punycode([["Pro\x10Dprost\x11Bnemluví\x10D""esky"]], 
              [["Proprostnemluvesky-uyb24dma41a"]]) // D 
test_punycode([["\x5DC\x5DE\x5D4\x5D4\x5DD\x5E4\x5E9\x5D5\x5D8\x5DC\x5D0" 
                "\x5DE\x5D3\x5D1\x5E8\x5D9\x5DD\x5E2\x5D1\x5E8\x5D9\x5EA"]], 
              [["4dbcagdahymbxekheh6e0a7fei0b"]]) // E 
test_punycode([["\x92F\x939\x932\x94B\x917\x939\x93F\x928\x94D\x926\x940" 
                "\x915\x94D\x92F\x94B\x902\x928\x939\x940\x902\x92C\x94B" 
                "\x932\x938\x915\x924\x947\x939\x948\x902"]], 
              [["i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd"]]) // F 
test_punycode([["\x306A\x305C\x307F\x3093\x306A\x65E5\x672C\x8A9E\x3092" 
                "\x8A71\x3057\x3066\x304F\x308C\x306A\x3044\x306E\x304B"]], 
              [["n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa"]]) // G 
test_punycode([["\xC138\xACC4\xC758\xBAA8\xB4E0\xC0AC\xB78C\xB4E4\xC774" 
                "\xD55C\xAD6D\xC5B4\xB97C\xC774\xD574\xD55C\xB2E4\xBA74" 
                "\xC5BC\xB9C8\xB098\xC88B\xC744\xAE4C"]], 
              [["989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5j" 
                "psd879ccm6fea98c"]]) // H 
test_punycode([["\x43F\x43E\x447\x435\x43C\x443\x436\x435\x43E\x43D\x438" 
                "\x43D\x435\x433\x43E\x432\x43E\x440\x44F\x442\x43F\x43E" 
                "\x440\x443\x441\x441\x43A\x438"]], 
              [["b1abfaaepdrnnbgefbadotcwatmq2g4l"]]) // I 
test_punycode([["PorquénopuedensimplementehablarenEspañol"]], 
              [["PorqunopuedensimplementehablarenEspaol-fmd56a"]]) // J 
test_punycode([["T\x1EA1isaoh\x1ECDkhôngth\x1EC3""ch\x1EC9nóiti\x1EBFng" 
                "Vi\x1EC7t"]], 
              [["TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g"]]) // K 
test_punycode([["3\x5E74""B\x7D44\x91D1\x516B\x5148\x751F"]], 
              [["3B-ww4c5e180e575a65lsy2b"]]) // L 
test_puntcode([["\x5B89\x5BA4\x5948\x7F8E\x6075-with-SUPER-MONKEYS"]], 
              [["-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n"]]) // M 
test_punycode([["Hello-Another-Way-\x305D\x308C\x305E\x308C" 
                "\x306E\x5834\x6240"]], 
              [["Hello-Another-Way--fc4qua05auwb3674vfr0b"]]) // N 
test_punycode([["\x3072\x3068\x3064\x5C4B\x6839\x306E\x4E0B""2"]], 
              [["2-u9tlzr9756bt3uc0v"]]) // O 
test_punycode([["Maji\x3067Koi\x3059\x308B""5\x79D2\x524D"]], 
              [["MajiKoi5-783gue6qz075azm5e"]]) // P 
test_punycode([["\x30D1\x30D5\x30A3\x30FC""de\x30EB\x30F3\x30D0"]], 
              [["de-jg4avhby1noc0d"]]) // Q 
test_punycode([["\x305D\x306E\x30B9\x30D4\x30FC\x30C9\x3067"]], 
              [["d9juau41awczczp"]]) // R 
test_punycode([["-> $1.00 <-"]], [["-> $1.00 <--"]]) // S 
 
// Case check 
test_eq([[Standards.IDNA.Punycode.decode("b1abfaaepdrnnbgefbaDotcwatmq2g4l")]], 
        [["\x43F\x43E\x447\x435\x43C\x443\x436\x435\x43E\x43D\x438" 
          "\x43D\x435\x433\x43E\x432\x43E\x440\x44F\x442\x43F\x43E" 
          "\x440\x443\x441\x441\x43A\x438"]]) // I 
 
// - UUID 
test_eq(Standards.UUID.make_dns("www.widgets.com")->str(), 
        "3d813cbb-47fb-32ba-91df-831e1593ac29") 
test_eq(Standards.UUID.make_null()->str(), 
        "00000000-0000-0000-0000-000000000000") 
 
// - TLD 
test_equal(Standards.TLD.cc.se, "Sweden") 
test_true(Standards.TLD.generic.com) 
 
// - X509 
 
test_any_equal([[ 
  string pem = #"-----BEGIN CERTIFICATE----- 
MIICPDCCAaUCED9pHoGc8JpK83P/uUii5N0wDQYJKoZIhvcNAQEFBQAwXzELMAkG 
A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz 
cyAxIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2 
MDEyOTAwMDAwMFoXDTI4MDgwMjIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV 
BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAxIFB1YmxpYyBQcmlt 
YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN 
ADCBiQKBgQDlGb9to1ZhLZlIcfZn3rmN67eehoAKkQ76OCWvRoiC5XOooJskXQ0f 
zGVuDLDQVoQYh5oGmxChc9+0WDlrbsH2FdWoqD+qEgaNMax/sDTXjzRniAnNFBHi 
TkVWaR94AoDa3EeRKbs2yWNcxeDXLYd7obcysHswuiovMaruo2fa2wIDAQABMA0G 
CSqGSIb3DQEBBQUAA4GBAFgVKTk8d6PaXCUDfGD67gmZPCcQcMgMCeazh88K4hiW 
NWLMv5sneYlfycQJ9M61Hd8qveXbhpxoJeUwfLaJFf5n0a3hUKw8fGJLj7qE1xIV 
Gx/KXQ/BUpQqEZnae88MNhPVNdwQGVnqlMEAv3WP2fr9dgTbYruQagPZRjXZ+Hxb 
-----END CERTIFICATE-----"; 
  object o = Standards.PEM.Message(pem); 
  object t = Standards.X509.decode_certificate(o->body); 
  return ([ "der" : stringp(t->der), "version" : t->version, "serial":t->serial->digits(16), "algorithm":sprintf("%O",t->algorithm[0]), "issuer":t->issuer[2][0][1]->value, "not_after":t->not_after, "not_before":t->not_before, "subject":t->subject[2][0][1]->value, "issuer_id":t->extensions]) 
]],[[ 
([ /* 9 elements */ 
  "algorithm": "Standards.ASN1.Types.Identifier(1.2.840.113549.1.1.5)", 
  "der": 1, 
  "issuer": "Class 1 Public Primary Certification Authority", 
  "issuer_id": 0, 
  "not_after": ([ /* 6 elements */ 
      "hour": 23, 
      "mday": 2, 
      "min": 59, 
      "mon": 7, 
      "sec": 59, 
      "year": 128 
    ]), 
  "not_before": ([ /* 6 elements */ 
      "hour": 0, 
      "mday": 29, 
      "min": 0, 
      "mon": 0, 
      "sec": 0, 
      "year": 96 
    ]), 
  "serial": "3f691e819cf09a4af373ffb948a2e4dd", 
  "subject": "Class 1 Public Primary Certification Authority", 
  "version": 1 
]) 
]]) 
 
END_MARKER