Compare commits
3 Commits
v0.0.3
...
fix-static
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daffaef0db | ||
|
|
95cb7074c4 | ||
|
|
2985033078 |
@@ -5,6 +5,7 @@ language: go
|
||||
|
||||
go:
|
||||
- 1.11.x
|
||||
- 1.15.x
|
||||
|
||||
env:
|
||||
global:
|
||||
|
||||
@@ -14,7 +14,7 @@ type Encoder struct {
|
||||
func NewEncoder(base Encoding) (Encoder, error) {
|
||||
_, ok := EncodingToStr[base]
|
||||
if !ok {
|
||||
return Encoder{-1}, fmt.Errorf("Unsupported multibase encoding: %d", base)
|
||||
return Encoder{-1}, fmt.Errorf("unsupported multibase encoding: %d", base)
|
||||
}
|
||||
return Encoder{base}, nil
|
||||
}
|
||||
@@ -33,9 +33,9 @@ func MustNewEncoder(base Encoding) Encoder {
|
||||
// either be the multibase name or single character multibase prefix
|
||||
func EncoderByName(str string) (Encoder, error) {
|
||||
var base Encoding
|
||||
ok := true
|
||||
var ok bool
|
||||
if len(str) == 0 {
|
||||
return Encoder{-1}, fmt.Errorf("Empty multibase encoding")
|
||||
return Encoder{-1}, fmt.Errorf("empty multibase encoding")
|
||||
} else if len(str) == 1 {
|
||||
base = Encoding(str[0])
|
||||
_, ok = EncodingToStr[base]
|
||||
@@ -43,7 +43,7 @@ func EncoderByName(str string) (Encoder, error) {
|
||||
base, ok = Encodings[str]
|
||||
}
|
||||
if !ok {
|
||||
return Encoder{-1}, fmt.Errorf("Unsupported multibase encoding: %s", str)
|
||||
return Encoder{-1}, fmt.Errorf("unsupported multibase encoding: %s", str)
|
||||
}
|
||||
return Encoder{base}, nil
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func Encode(base Encoding, data []byte) (string, error) {
|
||||
switch base {
|
||||
case Identity:
|
||||
// 0x00 inside a string is OK in golang and causes no problems with the length calculation.
|
||||
return string(Identity) + string(data), nil
|
||||
return string(rune(Identity)) + string(data), nil
|
||||
case Base2:
|
||||
return string(Base2) + binaryEncodeToString(data), nil
|
||||
case Base16:
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestMap(t *testing.T) {
|
||||
|
||||
var sampleBytes = []byte("Decentralize everything!!!")
|
||||
var encodedSamples = map[Encoding]string{
|
||||
Identity: string(0x00) + "Decentralize everything!!!",
|
||||
Identity: string(rune(0x00)) + "Decentralize everything!!!",
|
||||
Base2: "00100010001100101011000110110010101101110011101000111001001100001011011000110100101111010011001010010000001100101011101100110010101110010011110010111010001101000011010010110111001100111001000010010000100100001",
|
||||
Base16: "f446563656e7472616c697a652065766572797468696e67212121",
|
||||
Base16Upper: "F446563656E7472616C697A652065766572797468696E67212121",
|
||||
@@ -91,22 +91,22 @@ func TestRoundTrip(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
_, _, err := Decode(string(base) + "\u00A0")
|
||||
_, _, err := Decode(string(rune(base)) + "\u00A0")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on low-unicode")
|
||||
}
|
||||
|
||||
_, _, err = Decode(string(base) + "\u1F4A8")
|
||||
_, _, err = Decode(string(rune(base)) + "\u1F4A8")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on emoji")
|
||||
}
|
||||
|
||||
_, _, err = Decode(string(base) + "!")
|
||||
_, _, err = Decode(string(rune(base)) + "!")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on punctuation")
|
||||
}
|
||||
|
||||
_, _, err = Decode(string(base) + "\xA0")
|
||||
_, _, err = Decode(string(rune(base)) + "\xA0")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on high-latin1")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user