mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-30 19:51:58 +00:00
Add typo detector test, fix panics
This commit is contained in:
@@ -122,6 +122,11 @@ func (c WordCodec) BytesToWords(raw []byte) (words []string, err error) {
|
||||
|
||||
func (c WordCodec) WordsToBytes(words []string) ([]byte, error) {
|
||||
l := len(words)
|
||||
|
||||
if l == 0 {
|
||||
return nil, errors.New("Didn't provide any words")
|
||||
}
|
||||
|
||||
n2048 := big.NewInt(2048)
|
||||
nData := big.NewInt(0)
|
||||
// since we output words based on the remainder, the first word has the lowest
|
||||
@@ -143,6 +148,9 @@ func (c WordCodec) WordsToBytes(words []string) ([]byte, error) {
|
||||
// copy into the container we have with the expected size
|
||||
outLen, flex := bytelenFromWords(len(words))
|
||||
toCheck := make([]byte, outLen)
|
||||
if len(dataBytes) > outLen {
|
||||
return nil, errors.New("Invalid data, could not have been generated by this codec")
|
||||
}
|
||||
copy(toCheck[outLen-len(dataBytes):], dataBytes)
|
||||
|
||||
// validate the checksum...
|
||||
|
Reference in New Issue
Block a user