Add B32Decode()
This commit is contained in:
parent
8f34a06adf
commit
81c0d66f54
|
@ -8,6 +8,7 @@ Don't use the Go version yet. If you want sommething stable, there is a [Ruby ve
|
|||
|
||||
# TODO
|
||||
|
||||
- [ ] Add a real testing lib to DRY things up.
|
||||
- [ ] Get a good CI system going? Run tests at PR time, prevent coverage slips, etc..
|
||||
- [ ] Finish all the things below:
|
||||
|
||||
|
|
|
@ -33,5 +33,11 @@ func B32Encode(data []byte) string {
|
|||
// B32Decode takes a Crockford Base32 string and converts it
|
||||
// to a byte array.
|
||||
func B32Decode(input string) []byte {
|
||||
return []byte("WIP")
|
||||
output, error := Encoder.DecodeString(input)
|
||||
if error != nil {
|
||||
msg := fmt.Sprintf("Error decoding Base32 string %s", input)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
|
|
@ -63,3 +63,19 @@ func TestB32Encode(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestB32Decode(t *testing.T) {
|
||||
for i, test := range tests {
|
||||
actual := B32Decode(test.encoded)
|
||||
expected := test.decoded
|
||||
if len(actual) != len(expected) {
|
||||
fmt.Printf("\nFAIL: length mismatch at tests[%d]", i)
|
||||
t.Fail()
|
||||
}
|
||||
for j, x := range expected {
|
||||
if actual[j] != x {
|
||||
fmt.Printf("tests[%d].encoded[%d] did not decode B32 properly (%s)", j, i, test.encoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue