Added binary codec base58 as well as improving the help for --binary-codec flag (#548)
* Added binary codec `base58` as well as improving the help for `--binary-codec` flag * Added tests for base58 * Fixed tests Co-authored-by: Matthieu Vachon <matt@streamingfast.io>
This commit is contained in:
@@ -4,11 +4,14 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
)
|
||||
|
||||
const (
|
||||
CodecNone = "none"
|
||||
CodecHex = "hex"
|
||||
CodecBase58 = "base58"
|
||||
CodecBase64 = "base64"
|
||||
)
|
||||
|
||||
@@ -19,7 +22,7 @@ var (
|
||||
|
||||
func SetBinaryCodec(codec string) error {
|
||||
switch codec {
|
||||
case CodecNone, CodecHex, CodecBase64:
|
||||
case CodecNone, CodecHex, CodecBase58, CodecBase64:
|
||||
BinaryCodec = codec
|
||||
default:
|
||||
return fmt.Errorf("invalid binary codec: %v", codec)
|
||||
@@ -32,6 +35,8 @@ func encodeBinaryData(data []byte, codec string) string {
|
||||
switch codec {
|
||||
case CodecHex:
|
||||
return hex.EncodeToString(data)
|
||||
case CodecBase58:
|
||||
return base58.Encode(data)
|
||||
case CodecBase64:
|
||||
return base64.StdEncoding.EncodeToString(data)
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user