Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

I2OSP should return error for invalid n #19

Open
seebs opened this issue Dec 15, 2021 · 0 comments
Open

I2OSP should return error for invalid n #19

seebs opened this issue Dec 15, 2021 · 0 comments

Comments

@seebs
Copy link

seebs commented Dec 15, 2021

The IETF spec describing the I2OSP function describes it as returning an error for invalid (too small) n. This would probably make sense; otherwise, it produces truncated results. e.g., I2OSP(65536, 2) produces 0x01, 0x00, which would be converted back to 256, not 65536.

It might be possible to do this more cleanly with math/bits.Len64() and encoding/binary/BigEndian.PutUint64.

The direct uses of this function in the library don't seem to run into this (they're mostly calling it with small values like 0, 1, or the length in bytes of a hash), but since the symbol is exported, and the library's stated goal is to be hard-to-misuse, it should probably be returning an error explicitly when invoked with invalid parameters.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant