@@ -32,7 +32,8 @@ const encoded = [
32
32
[ 'base64pad' , 'MRGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchIQ==' ] ,
33
33
[ 'base64url' , 'uRGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchIQ' ] ,
34
34
[ 'base64urlpad' , 'URGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchIQ==' ] ,
35
- [ 'base256emoji' , '🚀💛✋💃✋😻😈🥺🤤🍀🌟💐✋😅✋💦✋🥺🏃😈😴🌟😻😝👏👏' ]
35
+ [ 'base256emoji' , '🚀💛✋💃✋😻😈🥺🤤🍀🌟💐✋😅✋💦✋🥺🏃😈😴🌟😻😝👏👏' ] ,
36
+ [ 'proquint' , 'pro-hidoj-katoj-kunuh-lanod-kudon-lonoj-fadoj-linoj-lanun-lidom-kojov-kisod-fah' ]
36
37
]
37
38
} ,
38
39
{
@@ -62,7 +63,8 @@ const encoded = [
62
63
[ 'base64pad' , 'MeWVzIG1hbmkgIQ==' ] ,
63
64
[ 'base64url' , 'ueWVzIG1hbmkgIQ' ] ,
64
65
[ 'base64urlpad' , 'UeWVzIG1hbmkgIQ==' ] ,
65
- [ 'base256emoji' , '🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ]
66
+ [ 'base256emoji' , '🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ] ,
67
+ [ 'proquint' , 'pro-lojoj-lasob-kujod-kunon-fabod' ]
66
68
]
67
69
} ,
68
70
{
@@ -92,7 +94,8 @@ const encoded = [
92
94
[ 'base64pad' , 'MaGVsbG8gd29ybGQ=' ] ,
93
95
[ 'base64url' , 'uaGVsbG8gd29ybGQ' ] ,
94
96
[ 'base64urlpad' , 'UaGVsbG8gd29ybGQ=' ] ,
95
- [ 'base256emoji' , '🚀😴✋🍀🍀😓😅✔😓🥺🍀😳' ]
97
+ [ 'base256emoji' , '🚀😴✋🍀🍀😓😅✔😓🥺🍀😳' ] ,
98
+ [ 'proquint' , 'pro-kodoj-kudos-kusob-litoz-lanos-kib' ]
96
99
]
97
100
} ,
98
101
{
@@ -122,7 +125,8 @@ const encoded = [
122
125
[ 'base64pad' , 'MAHllcyBtYW5pICE=' ] ,
123
126
[ 'base64url' , 'uAHllcyBtYW5pICE' ] ,
124
127
[ 'base64urlpad' , 'UAHllcyBtYW5pICE=' ] ,
125
- [ 'base256emoji' , '🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ]
128
+ [ 'base256emoji' , '🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ] ,
129
+ [ 'proquint' , 'pro-badun-kijug-fadot-kajov-kohob-fah' ]
126
130
]
127
131
} ,
128
132
{
@@ -152,13 +156,30 @@ const encoded = [
152
156
[ 'base64pad' , 'MAAB5ZXMgbWFuaSAh' ] ,
153
157
[ 'base64url' , 'uAAB5ZXMgbWFuaSAh' ] ,
154
158
[ 'base64urlpad' , 'UAAB5ZXMgbWFuaSAh' ] ,
155
- [ 'base256emoji' , '🚀🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ]
159
+ [ 'base256emoji' , '🚀🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ] ,
160
+ [ 'proquint' , 'pro-babab-lojoj-lasob-kujod-kunon-fabod' ]
156
161
]
157
162
} ,
163
+
164
+ // RFC9285 examples
158
165
{ input : 'AB' , tests : [ [ 'base45' , 'RBB8' ] ] } ,
159
166
{ input : 'Hello!!' , tests : [ [ 'base45' , 'R%69 VD92EX0' ] ] } ,
160
167
{ input : 'base-45' , tests : [ [ 'base45' , 'RUJCLQE7W581' ] ] } ,
161
- { input : 'ietf!' , tests : [ [ 'base45' , 'RQED8WEX0' ] ] }
168
+ { input : 'ietf!' , tests : [ [ 'base45' , 'RQED8WEX0' ] ] } ,
169
+
170
+ // proquint spec examples, IPv4 addresses
171
+ { input : Uint8Array . from ( [ 127 , 0 , 0 , 1 ] ) , tests : [ [ 'proquint' , 'pro-lusab-babad' ] ] } , // 127.0.0.1
172
+ { input : Uint8Array . from ( [ 63 , 84 , 220 , 193 ] ) , tests : [ [ 'proquint' , 'pro-gutih-tugad' ] ] } , // 63.84.220.193
173
+ { input : Uint8Array . from ( [ 63 , 118 , 7 , 35 ] ) , tests : [ [ 'proquint' , 'pro-gutuk-bisog' ] ] } , // 63.118.7.35
174
+ { input : Uint8Array . from ( [ 140 , 98 , 193 , 141 ] ) , tests : [ [ 'proquint' , 'pro-mudof-sakat' ] ] } , // 140.98.193.141
175
+ { input : Uint8Array . from ( [ 64 , 255 , 6 , 200 ] ) , tests : [ [ 'proquint' , 'pro-haguz-biram' ] ] } , // 64.255.6.200
176
+ { input : Uint8Array . from ( [ 128 , 30 , 52 , 45 ] ) , tests : [ [ 'proquint' , 'pro-mabiv-gibot' ] ] } , // 128.30.52.45
177
+ { input : Uint8Array . from ( [ 147 , 67 , 119 , 2 ] ) , tests : [ [ 'proquint' , 'pro-natag-lisaf' ] ] } , // 147.67.119.2
178
+ { input : Uint8Array . from ( [ 212 , 58 , 253 , 68 ] ) , tests : [ [ 'proquint' , 'pro-tibup-zujah' ] ] } , // 212.58.253.68
179
+ { input : Uint8Array . from ( [ 216 , 35 , 68 , 215 ] ) , tests : [ [ 'proquint' , 'pro-tobog-higil' ] ] } , // 216.35.68.215
180
+ { input : Uint8Array . from ( [ 216 , 68 , 232 , 21 ] ) , tests : [ [ 'proquint' , 'pro-todah-vobij' ] ] } , // 216.68.232.21
181
+ { input : Uint8Array . from ( [ 198 , 81 , 129 , 136 ] ) , tests : [ [ 'proquint' , 'pro-sinid-makam' ] ] } , // 198.81.129.136
182
+ { input : Uint8Array . from ( [ 12 , 110 , 110 , 204 ] ) , tests : [ [ 'proquint' , 'pro-budov-kuras' ] ] } // 12.110.110.204
162
183
]
163
184
164
185
describe ( 'spec test' , ( ) => {
@@ -169,13 +190,15 @@ describe('spec test', () => {
169
190
const base = bases [ name as keyof typeof bases ]
170
191
171
192
describe ( name , ( ) => {
193
+ const byteInput = typeof input === 'string' ? fromString ( input ) : input
194
+
172
195
it ( `should encode from buffer [${ input } ]` , ( ) => {
173
- const out = base . encode ( fromString ( input ) )
196
+ const out = base . encode ( byteInput )
174
197
assert . deepStrictEqual ( out , output )
175
198
} )
176
199
177
200
it ( `should decode from string [${ input } ]` , ( ) => {
178
- assert . deepStrictEqual ( base . decode ( output ) , fromString ( input ) )
201
+ assert . deepStrictEqual ( base . decode ( output ) , byteInput )
179
202
} )
180
203
} )
181
204
}
@@ -187,6 +210,10 @@ describe('spec test', () => {
187
210
if ( base . name === 'identity' ) {
188
211
return this . skip ( )
189
212
}
213
+ if ( base . name === 'proquint' ) {
214
+ assert . throws ( ( ) => base . decode ( 'pro-^!@$%!#$%@#y' ) , `Non-${ base . name } character` )
215
+ return
216
+ }
190
217
191
218
assert . throws ( ( ) => base . decode ( base . prefix + '^!@$%!#$%@#y' ) , `Non-${ base . name } character` )
192
219
} )
@@ -196,4 +223,14 @@ describe('spec test', () => {
196
223
// not enough input chars, should be multiple of 3 or multiple of 3 + 2
197
224
assert . throws ( ( ) => bases . base45 . decode ( 'R%69 VD92EX' ) , 'Unexpected end of data' )
198
225
} )
226
+
227
+ it ( 'proquint should fail with invalid input' , ( ) => {
228
+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-' ) , 'Unexpected end of data' )
229
+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-f' ) , 'Unexpected end of data' )
230
+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-fa' ) , 'Unexpected end of data' )
231
+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-fabo' ) , 'Unexpected end of data' )
232
+ assert . throws ( ( ) => bases . proquint . decode ( 'plojoj-lasob-kujod-kunon-fabod' ) , 'Invalid proquint string' )
233
+ assert . throws ( ( ) => bases . proquint . decode ( 'prlojoj-lasob-kujod-kunon-fabod' ) , 'Invalid proquint string' )
234
+ assert . throws ( ( ) => bases . proquint . decode ( 'prolojoj-lasob-kujod-kunon-fabod' ) , 'Invalid proquint string' )
235
+ } )
199
236
} )
0 commit comments