rust-bitcoin / rust-bech32

Bech32 format encoding and decoding
MIT License
94 stars 49 forks source link

Alternative fes_to_bytes_zeropad with no dropping of last bits #201

Closed optout21 closed 1 month ago

optout21 commented 1 month ago

Fixes #198 , as discussed there

apoelstra commented 1 month ago

In 15f6d0ed1fc29a93cd23505a8d629365d01a5bf2:

The change to the doccomment starting with "If the total number of bits" is wrong. (Though I agree this sentence is really long, and if you can break it up somehow, you should.)

Otherwise ack.

CI failure is unrelated and is fixed by #200 (which I will merge shortly, so you will just need to rebase).

optout21 commented 1 month ago

The change to the doccomment starting with "If the total number of bits" is wrong. (Though I agree this sentence is really long, and if you can break it up somehow, you should.)

I changed the documentation, made the explanation more detailed. Let me know if it's OK; should I squash.

    /// Similar to `fes_to_bytes`, but in this variant trailing bits are kept.
    ///
    /// If the last bits do not fill up the last output byte completely, they
    /// are not dropped, but kept, and the last byte is padded with zero bits.
    /// In effect this is the same as if the input was padded with zero values
    /// (1 or 2), such that there are enough zero bits to fill the last byte.
    /// The output is either the same as of `fes_to_bytes`, or has 1 extra byte.
apoelstra commented 1 month ago

New text looks great! Nah, I wouldn't bother squashing.

apoelstra commented 1 month ago

Will let @clarkmoody review before merging since this is an API change.