Skip to content

Add method to check for decoding errors - #287

Open
tcerqueira wants to merge 2 commits into
marshallpierce:masterfrom
tcerqueira:feat/check-encoding
Open

Add method to check for decoding errors#287
tcerqueira wants to merge 2 commits into
marshallpierce:masterfrom
tcerqueira:feat/check-encoding

Conversation

@tcerqueira

@tcerqueira tcerqueira commented Jun 21, 2025

Copy link
Copy Markdown

Feature for #286

  • Add check_encoded method to Engine trait.
  • Implement feature for all engines.
  • Add tests
  • Add benchmarks

The tests decode_invalid_trailing_bytes are failing because the error for decoding does not match with check implementation. I don't know if it's necessarily incorrect but it's definitely less useful error compared to the decode implementation. Either way, I think the check should error the same way as decode, for everyone's sanity.

The msrv build fails because of range pattern syntax.

@tcerqueira

Copy link
Copy Markdown
Author

@marshallpierce do you have any suggestion on the best solution to throw the proper error?

@tcerqueira

Copy link
Copy Markdown
Author

Benchamarks show it's slower than decode_slice 🥀

@apasel422

Copy link
Copy Markdown

What's the status of this? I'm interested in the new functionality myself.

@tcerqueira

Copy link
Copy Markdown
Author

@apasel422 Stale. Use decode_slice and ignore what was written to the buffer.

@apasel422

Copy link
Copy Markdown

@apasel422 Stale. Use decode_slice and ignore what was written to the buffer.

Doesn't that require allocating a slice of sufficient size to avoid hitting an error?

@marshallpierce

Copy link
Copy Markdown
Owner

Sorry I haven't gotten to this; real life has been demanding.

You could use DecoderReader to read base64, throwing away the decoded output one byte or chunk at a time. If it succeeds to the end, it's valid, without having to have enough space for the whole thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants