bases.encoding.simple
Simple base encodings.
Encoding of a bytestring b:
if
bcontains any leading zero bytes, raisesEncodingErrorconverts
bto an unsigned integeri(big-endian)converts
ito the encoding base, using the encoding alphabet for digits
Decoding of a string s:
if
scontains any leading zero characters, raisesDecodingErrorconverts
sto an unsigned integeri, using the encoding alphabet for digits of the encoding baseconverts
ito its minimal byte representation (big-endian)
SimpleBaseEncoding
- class SimpleBaseEncoding(alphabet, *, case_sensitive=None)[source]
Bases:
BaseEncodingSimple base encodings.
- Parameters:
- canonical_bytes(b)[source]
Returns a canonical version of the bytestring
b: this is the bytestring obtained by first encodingband then decoding it.(This method is overridden by subclasses with more efficient implementations.)
- Parameters:
b (
BytesLike) – the bytestring- Return type:
- canonical_string(s)[source]
Returns a canonical version of the string
s: this is the string obtained by first decodingsand then encoding it.(This method is overridden by subclasses with more efficient implementations.)