-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.21.0: decode_slice: Unexpected behavior for exact-size output slice #212
Comments
I observe the same behavior when I construct the engine so that it requires no padding: const ENC: base64::engine::GeneralPurpose =
base64::engine::general_purpose::GeneralPurpose::new(
&base64::alphabet::URL_SAFE,
base64::engine::general_purpose::GeneralPurposeConfig::new()
.with_encode_padding(false)
.with_decode_padding_mode(base64::engine::DecodePaddingMode::RequireNone),
); |
It is documented while it seems surprising. Line 307 in d7fb31c
|
Yes, it is expected. There's #210 to track having a precise decode size check, but in the meantime if you want the old behavior (no error, just panic), use |
Well, to be on the safe side, I think perhaps it makes sense to check the input slice actually decodes to the desired length. Is there any way to compute the length of the decoded value from the length of the encoded value? |
Anywho, thanks for linking the relevant issue. I'll close this as duplicate :) |
If there was, it'd already be done. :) Unfortunately it requires doing at least a partial decode to get a precise answer, which adds overhead and complexity. |
Boy Base64 is a hairy spec. |
Surprisingly so, for such a simple thing... padding ruins everything. |
Closing as a dup of #210. |
For me I'm trying to decode 16 bytes of base64. When I use What I wanted was I imagine everyone decoding into a slice runs into this problem. |
Hmm... can you show more details about what you're trying to do? Ideally in the form of a branch with a failing test. :) |
How am I going to show a failing test for a confusing UX?
That's the code I was trying to write. By critique here is that getting to So potential solutions,
But I can't see creating a failing test for any of these. It's just a rough area in the UX. |
I noticed some behavior with
STANDARD_NO_PAD
that I didn't expect (similarly forURL_SAFE_NO_PAD
). In the code below, I encode a 32 byte string, then usedecode_slice()
to read it into a buffer.Is this behavior expected? If so, is it documented anywhere?
The text was updated successfully, but these errors were encountered: