Even more tests/benchmarks, less repetition in-code

This commit is contained in:
Peter Rabbitson
2020-05-22 03:43:29 +02:00
parent c03399abc2
commit aa5d547a81
2 changed files with 142 additions and 62 deletions

View File

@@ -37,29 +37,8 @@ const (
Base64urlPad = 'U'
)
// Encodings is a map of the supported encoding, unsupported encoding
// EncodingToStr is a map of the supported encoding, unsupported encoding
// specified in standard are left out
var Encodings = map[string]Encoding{
"identity": 0x00,
"base2": '0',
"base16": 'f',
"base16upper": 'F',
"base32": 'b',
"base32upper": 'B',
"base32pad": 'c',
"base32padupper": 'C',
"base32hex": 'v',
"base32hexupper": 'V',
"base32hexpad": 't',
"base32hexpadupper": 'T',
"base58flickr": 'Z',
"base58btc": 'z',
"base64": 'm',
"base64url": 'u',
"base64pad": 'M',
"base64urlpad": 'U',
}
var EncodingToStr = map[Encoding]string{
0x00: "identity",
'0': "base2",
@@ -73,14 +52,22 @@ var EncodingToStr = map[Encoding]string{
'V': "base32hexupper",
't': "base32hexpad",
'T': "base32hexpadupper",
'Z': "base58flickr",
'z': "base58btc",
'Z': "base58flickr",
'm': "base64",
'u': "base64url",
'M': "base64pad",
'U': "base64urlpad",
}
var Encodings = map[string]Encoding{}
func init() {
for e, n := range EncodingToStr {
Encodings[n] = e
}
}
// ErrUnsupportedEncoding is returned when the selected encoding is not known or
// implemented.
var ErrUnsupportedEncoding = fmt.Errorf("selected encoding not supported")