To reproduce the issue please use convert/bigendian/convert.go previous version
func TestBigEndianConvertion(t *testing.T) {
totp, err := NewTOTP("info@sec51.com", "Sec51", crypto.SHA256, 6)
if err != nil {
t.Fatal(err)
}
data, err := totp.ToBytes()
if err != nil {
t.Fatal(err)
}
newTotp, err := TOTPFromBytes(data, "Sec51")
if err != nil {
t.Fatal(err)
}
if totp.account != newTotp.account {
t.Error("Fail: Received totp do not match origin")
}
}
Fails with:
panic: runtime error: slice bounds out of range [recovered]
panic: runtime error: slice bounds out of range
This is because reading issuerSize returns 0 although the byte array is ok.
The issue is in the implementation of
// helper function which converts a big endian []byte to a int
func FromInt(data [4]byte) int {
i := (int(data[3]) << 0) | (int(data[2]) << 8) |
(int(data[1]) << 16) | (int(data[0]) << 24)
return int(i)
}
Have same issue
To reproduce the issue please use convert/bigendian/convert.go previous version
Fails with: panic: runtime error: slice bounds out of range [recovered] panic: runtime error: slice bounds out of range
This is because reading
issuerSize
returns 0 although the byte array is ok.The issue is in the implementation of
To Fix: just update latest version of convert library
The big question is why adding a Println of data in FromInt, makes the function to work fine