5377
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2018 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
4744
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
Base64Coder subclass:#Base64UrlCoder
|
|
17 |
instanceVariableNames:''
|
|
18 |
classVariableNames:'Base64UrlMapping Base64UrlReverseMapping'
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'System-Storage'
|
|
21 |
!
|
|
22 |
|
|
23 |
!Base64UrlCoder class methodsFor:'documentation'!
|
|
24 |
|
5377
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2018 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
|
|
37 |
"
|
|
38 |
!
|
|
39 |
|
4744
|
40 |
documentation
|
|
41 |
"
|
|
42 |
A variant of base64 encoding which generates url- and filename save encodings.
|
|
43 |
Same as Base64 except that instead of plus and slash, minus and underline are generated.
|
|
44 |
|
|
45 |
The main entry point API is
|
|
46 |
Base64UrlCoder encode:aStringOrBytes
|
|
47 |
and
|
|
48 |
Base64UrlCoder decode:aString
|
|
49 |
|
|
50 |
If the decoder should return a string, use
|
|
51 |
Base64UrlCoder decodeAsString:aString.
|
|
52 |
|
|
53 |
[author:]
|
|
54 |
Claus Gittinger
|
|
55 |
|
|
56 |
[see also:]
|
|
57 |
RFC https://tools.ietf.org/html/rfc4648
|
|
58 |
|
|
59 |
[instance variables:]
|
|
60 |
|
|
61 |
[class variables:]
|
|
62 |
Base64UrlMapping String Mapping from bytes (with 6 valid bits)
|
|
63 |
to Base64Url characters
|
|
64 |
Base64UrlReverseMapping Array Mapping from Base64Url characters to 6-bit-Bytes
|
|
65 |
"
|
|
66 |
!
|
|
67 |
|
|
68 |
examples
|
|
69 |
"
|
|
70 |
[exBegin]
|
|
71 |
(Base64Coder encode:#[0 0 16r3F]) = 'AAA/'
|
|
72 |
[exEnd]
|
|
73 |
[exBegin]
|
|
74 |
(Base64Coder decode:'AAA/') = #[0 0 63]
|
|
75 |
[exEnd]
|
|
76 |
|
|
77 |
[exBegin]
|
|
78 |
(Base64UrlCoder encode:#[0 0 16r3F]) = 'AAA_'
|
|
79 |
[exEnd]
|
|
80 |
[exBegin]
|
|
81 |
(Base64UrlCoder decode:'AAA_') = #[0 0 63]
|
|
82 |
[exEnd]
|
|
83 |
"
|
|
84 |
! !
|
|
85 |
|
|
86 |
!Base64UrlCoder class methodsFor:'initialization'!
|
|
87 |
|
|
88 |
initializeMappings
|
|
89 |
"initialize class variables"
|
|
90 |
|
|
91 |
Base64UrlMapping isNil ifTrue:[
|
|
92 |
"65 characters representing the 6-bit values from 0-63 and one pad character"
|
|
93 |
"/ notice: minus and underline instead of plus and slash
|
|
94 |
Base64UrlMapping := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_='.
|
|
95 |
Base64UrlReverseMapping := self reverseMappingFor:Base64UrlMapping.
|
|
96 |
].
|
|
97 |
|
|
98 |
"
|
|
99 |
Base64UrlMapping := nil.
|
|
100 |
self initializeMappings
|
|
101 |
"
|
|
102 |
|
|
103 |
"Created: / 30-09-2018 / 15:20:47 / Claus Gittinger"
|
|
104 |
!
|
|
105 |
|
|
106 |
mapping
|
|
107 |
^ Base64UrlMapping
|
|
108 |
|
|
109 |
"Created: / 30-09-2018 / 15:31:14 / Claus Gittinger"
|
|
110 |
!
|
|
111 |
|
|
112 |
reverseMapping
|
|
113 |
^ Base64UrlReverseMapping
|
|
114 |
|
|
115 |
"Created: / 30-09-2018 / 15:31:21 / Claus Gittinger"
|
|
116 |
! !
|
|
117 |
|
|
118 |
!Base64UrlCoder class methodsFor:'documentation'!
|
|
119 |
|
|
120 |
version_CVS
|
|
121 |
^ '$Header$'
|
|
122 |
! !
|
|
123 |
|