|
Class: Base32Coder
Object
|
+--Visitor
|
+--AspectVisitor
|
+--ObjectCoder
|
+--BaseNCoder
|
+--Base32Coder
- Package:
- stx:libbasic2
- Category:
- System-Storage
- Version:
- rev:
1.9
date: 2024/01/29 20:32:43
- user: cg
- file: Base32Coder.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
Instances of this class perform Base32 en- and decoding as defined in RFC 3548
5 bytes are mapped to 8 characters, representing 5 bits each.
[instance variables:]
[class variables:]
Base32Mapping String Mapping from bytes (with 5 valid bits)
to Base32 characters
Base32ReverseMapping Array Mapping from Base32 characters to 5-bit-Bytes
copyrightCOPYRIGHT (c) 2002 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
initialization
-
initializeMappings
-
initialize class variables
Usage example(s):
Base32Mapping := nil.
self initializeMappings
|
-
mapping
-
-
reverseMapping
-
encoding
-
nextPutByte: aByte
-
encode aByte on the output stream
misc
-
flush
-
flush the remaining bits of buffer.
The number of bits in buffer is not a multiple of 6, so we pad
the buffer and signal that padding has been done via $= characters.
private
-
fillBuffer
-
fill buffer with next 8 characters each representing 5 bits
|data1 text data2|
data1 := #[0 1 16r7F 16r80 16r81 16rFE 16rFF].
text := Base32Coder encode:data1.
data2 := Base32Coder decode:text.
self assert:(data2 = data1)
|
|coder|
coder := Base32Coder on:'' writeStream.
coder nextPutAll:#[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19].
coder flush.
coder contents inspect.
coder reset.
coder nextPut:254.
coder contents inspect.
|
|coder decoder|
coder := Base32Coder on:'' writeStream.
coder nextPutAll:#[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20].
coder flush.
decoder := Base32Coder on:(coder contents readStream).
[decoder atEnd] whileFalse:[
Transcript show:decoder next
].
Transcript cr.
|
|coder|
coder := Base32Coder on:'' writeStream.
coder nextPutAll:(0 to:200) asByteArray.
coder flush.
Transcript showCR:(coder contents).
|
|bytes encoded decoded|
bytes := #[0 0 0] copy.
0 to:255 do:[:b1 |
Transcript showCR:b1.
bytes at:1 put:b1.
0 to:255 do:[:b2 |
bytes at:2 put:b2.
0 to:255 do:[:b3 |
bytes at:3 put:b3.
encoded := Base32Coder encode:bytes.
decoded := Base32Coder decode:encoded.
self assert:(decoded = bytes).
]
]
].
|
|