Conversation
cpu
left a comment
There was a problem hiding this comment.
Thanks! Here's a first pass.
Two higher-level items:
- It looks like this breaks
cargo test --no-default-features. - Could you add CI coverage for the no-std mode?
src/pemfile.rs
Outdated
| Base64Decode(DecodeError), | ||
| } | ||
|
|
||
| impl From<DecodeError> for Error { |
There was a problem hiding this comment.
This leaks the base64 crate into the public API no? I think one advantage of the previous approach was that it kept base64 internal.
There was a problem hiding this comment.
Indeed. we can't use the usual Box<dyn std::error::Error> replacement because this enum has to work in no-std context. the alternatives I see are
- drop the tuple field, i.e. simply use
Error::Base64Decode. this loses information - use
Base64Decode(Box<dyn core::fmt::Debug>). that trait object is not super common but it's close toBox<dyn Error>. however, it cannot be converted intoBox<dyn Error>as there's noFrom/Intotrait that glues the two trait object types - use
Base64Decode(String)where theStringis theformat!-ed version ofBase64Decode. unlikeBox<dyn Debug>this can be converted intoBox<dyn Error>using the?operator so that's a plus - basically copy
base64::DecodeErrorinto this crate and use that. that does not expose thebase64dependency but then you have to maintain a function that mapsbase64::DecodeErrorintopemfile::DecodeErrorand update it ifbase64::DecodeError(which is not marked as non_exhaustive) ever changes.
There was a problem hiding this comment.
@ctz and I yesterday were chatting that we might want to yeet the use of the base64 crate at the first sign of trouble (since we generally haven't been that happy with it) -- maybe that's this?
There was a problem hiding this comment.
use Base64Decode(String) where the String is the format!-ed version of Base64Decode. unlike Box this can be converted into Box using the ? operator so that's a plus
That option seems OK to me. I suspect there's not much value in downstream code being able to programmatically determine if the data was invalid for padding, length, unknown symbol etc. In most cases I expect the error is going to be displayed to a user in string form 🤔
There was a problem hiding this comment.
In most cases I expect the error is going to be displayed to a user in string form
I agree. this is not the case where knowing the exact error cause is going to let the user fix the input and retry the operation. most likely, malformed pem files are going to be skipped or result in a fatal error.
|
@cpu thanks for the review. I have addressed your comments in new commits to ease the review process. I can squash the commits when you are all happy with the final version |
|
I forgot to explicit answer to this:
given that the
done |
SGTM! Thank you.
From my perspective I think it's less about increasing coverage and more that I found it surprising that |
I've pushed a commit to make I think the expectation from the point of view of the contributor is that |
cpu
left a comment
There was a problem hiding this comment.
Thanks! Looks good to me once the From trait is fixed up.
814ee06 to
d0a0c67
Compare
|
I've squashed the commits |
|
I think this the
Additionally, I find the current order of items pretty confusing. Currently the order is kind of bottom-up (contra our conventions in other crates), but this PR then adds |
to make all non-core imports explicit
d0a0c67 to
2f674dd
Compare
|
Split the commits.
in a previous version it was masking the |
2f674dd to
089237b
Compare
|
I dropped the bit that disabled base64's "std" feature while splitting the commit (and CI still passed). I have updated CI (in the latest commit) to catch usage of libstd in dependencies. |
djc
left a comment
There was a problem hiding this comment.
Thanks for splitting, this is much better!
089237b to
7bc284f
Compare
|
@djc applied your suggestions |
this PR adds a new API,
read_one_from_slice, which works just likeread_onebut operates on a slice.this PR also adds an opt-out "std" Cargo feature. all the API that operates on IO objects is behind the "std" feature.
read_one_from_sliceis available in no-std mode.this PR is best reviewed on a commit-by-commit basis