4744
|
1 |
"{ Package: 'stx:libbasic2' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
Base64Coder subclass:#Base64UrlCoder
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:'Base64UrlMapping Base64UrlReverseMapping'
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'System-Storage'
|
|
10 |
!
|
|
11 |
|
|
12 |
!Base64UrlCoder class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
A variant of base64 encoding which generates url- and filename save encodings.
|
|
17 |
Same as Base64 except that instead of plus and slash, minus and underline are generated.
|
|
18 |
|
|
19 |
The main entry point API is
|
|
20 |
Base64UrlCoder encode:aStringOrBytes
|
|
21 |
and
|
|
22 |
Base64UrlCoder decode:aString
|
|
23 |
|
|
24 |
If the decoder should return a string, use
|
|
25 |
Base64UrlCoder decodeAsString:aString.
|
|
26 |
|
|
27 |
[author:]
|
|
28 |
Claus Gittinger
|
|
29 |
|
|
30 |
[see also:]
|
|
31 |
RFC https://tools.ietf.org/html/rfc4648
|
|
32 |
|
|
33 |
[instance variables:]
|
|
34 |
|
|
35 |
[class variables:]
|
|
36 |
Base64UrlMapping String Mapping from bytes (with 6 valid bits)
|
|
37 |
to Base64Url characters
|
|
38 |
Base64UrlReverseMapping Array Mapping from Base64Url characters to 6-bit-Bytes
|
|
39 |
"
|
|
40 |
!
|
|
41 |
|
|
42 |
examples
|
|
43 |
"
|
|
44 |
[exBegin]
|
|
45 |
(Base64Coder encode:#[0 0 16r3F]) = 'AAA/'
|
|
46 |
[exEnd]
|
|
47 |
[exBegin]
|
|
48 |
(Base64Coder decode:'AAA/') = #[0 0 63]
|
|
49 |
[exEnd]
|
|
50 |
|
|
51 |
[exBegin]
|
|
52 |
(Base64UrlCoder encode:#[0 0 16r3F]) = 'AAA_'
|
|
53 |
[exEnd]
|
|
54 |
[exBegin]
|
|
55 |
(Base64UrlCoder decode:'AAA_') = #[0 0 63]
|
|
56 |
[exEnd]
|
|
57 |
"
|
|
58 |
! !
|
|
59 |
|
|
60 |
!Base64UrlCoder class methodsFor:'initialization'!
|
|
61 |
|
|
62 |
initializeMappings
|
|
63 |
"initialize class variables"
|
|
64 |
|
|
65 |
Base64UrlMapping isNil ifTrue:[
|
|
66 |
"65 characters representing the 6-bit values from 0-63 and one pad character"
|
|
67 |
"/ notice: minus and underline instead of plus and slash
|
|
68 |
Base64UrlMapping := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_='.
|
|
69 |
Base64UrlReverseMapping := self reverseMappingFor:Base64UrlMapping.
|
|
70 |
].
|
|
71 |
|
|
72 |
"
|
|
73 |
Base64UrlMapping := nil.
|
|
74 |
self initializeMappings
|
|
75 |
"
|
|
76 |
|
|
77 |
"Created: / 30-09-2018 / 15:20:47 / Claus Gittinger"
|
|
78 |
!
|
|
79 |
|
|
80 |
mapping
|
|
81 |
^ Base64UrlMapping
|
|
82 |
|
|
83 |
"Created: / 30-09-2018 / 15:31:14 / Claus Gittinger"
|
|
84 |
!
|
|
85 |
|
|
86 |
reverseMapping
|
|
87 |
^ Base64UrlReverseMapping
|
|
88 |
|
|
89 |
"Created: / 30-09-2018 / 15:31:21 / Claus Gittinger"
|
|
90 |
! !
|
|
91 |
|
|
92 |
!Base64UrlCoder class methodsFor:'documentation'!
|
|
93 |
|
|
94 |
version_CVS
|
|
95 |
^ '$Header$'
|
|
96 |
! !
|
|
97 |
|