-
Notifications
You must be signed in to change notification settings - Fork 18
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
add no-std support #29
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
/Into
trait that glues the two trait object types - use
Base64Decode(String)
where theString
is 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::DecodeError
into this crate and use that. that does not expose thebase64
dependency but then you have to maintain a function that mapsbase64::DecodeError
intopemfile::DecodeError
and update it ifbase64::DecodeError
(which is not marked as non_exhaustive) ever changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_one
but 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_slice
is available in no-std mode.this PR is best reviewed on a commit-by-commit basis