-
Notifications
You must be signed in to change notification settings - Fork 165
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
Stop using time crate #44
Conversation
You can make one of these using `webpki::Time::from_seconds_from_unix_epoch`. - Move ASN1 conversion functions to "calendar.rs", and add some tests. - The new feature `use_std` adds `from<std::time::SystemTime>` to `webpki::Time`. - Fixate time in tests/integration to prevent future expiry. - Add a library-external test of `use_std` feature. - Run tests with `use_std` and without.
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.
Hi. Sorry about the long delay in reviewing this. In general this looks good though there are some minor issues that should be addressed. In particular, The most concerning to me is the the unwrap()
in the From
implementation.
If you won't have time to address the review comments soon (understandable, especially given the long delay), or if you'd rather just have me make them, please LMK and I'll take care of them.
@@ -1,13 +0,0 @@ | |||
alg-ecdsa-p256.der |
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. I got rid of this file in a separate commit.
@@ -21,7 +21,7 @@ license-file = "LICENSE" | |||
name = "webpki" | |||
readme = "README.md" | |||
repository = "https:/briansmith/webpki" | |||
version = "0.10.2" | |||
version = "0.11.0" |
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.
Let's just undo the version number. I'll bump the version number when I publish the new version on crates.io.
@@ -57,11 +57,11 @@ path = "src/webpki.rs" | |||
[features] | |||
default = ["trust_anchor_util"] | |||
trust_anchor_util = [] | |||
use_std = [] |
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.
Let's name this "std". See https://rust-lang-nursery.github.io/api-guidelines/naming.html#c-feature.
impl convert::From<time::SystemTime> for Time { | ||
fn from(st: time::SystemTime) -> Time { | ||
Time(st.duration_since(time::UNIX_EPOCH) | ||
.unwrap() // it's definitely after 1970 now |
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.
I was hoping that TryFrom
would be stable by now, but it isn't yet. Regardless, let's give this TryFrom
semantics by just adding a normal (non-trait) try_from
constructor in the impl Time
section that returns a Result
.
In particular, although it is true that it is definitely after 1970, we can't assume that the system will know that, especially on non-Unix systems that have an epoch that starts before the Unix epoch. So, unfortunately, this will need to be a fallible conversion the way it is written now.
|
||
impl convert::From<time::SystemTime> for Time { | ||
fn from(st: time::SystemTime) -> Time { | ||
Time(st.duration_since(time::UNIX_EPOCH) |
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.
Instead of constructing a Time
directly using its constructor, let's use the constructor function Time::from_seconds_from_unix_epoch()
.
#[cfg(feature = "use_std")] | ||
pub mod stdsupport { | ||
use std::time; | ||
use std::convert; |
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.
std::convert::From
is in the prelude so this use
isn't needed.
pub struct Time(u64); | ||
|
||
#[cfg(feature = "use_std")] | ||
pub mod stdsupport { |
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.
Why is it useful to put this into a stdsupport
submodule?
I think you created the stdsupport
submodule because we want to pub use stdsupport::*
in order to export the traits from the root module of the crate, right? That's reasonable, but let's document that here with a comment so that it is clear to readers.
However, until we have TryFrom
I think it's a moot point and we can just remove stdsupport
in favor of adding a try_from()
constructor function to Time
.
use std::convert; | ||
use super::Time; | ||
|
||
impl convert::From<time::SystemTime> for Time { |
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.
Unless I'm missing something, we don't need to qualify From
because it's in the prelude. For example we have impl From<untrusted::EndOfInput> for Unspecified { ... }
elsewhere.
|
||
#[cfg(feature = "use_std")] | ||
pub mod stdsupport { | ||
use std::time; |
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.
Let's just use std
and then qualify everything with an additional std::
, which, IIRC, is the style we've been using in ring and webpki up to this point.
pub mod stdsupport { | ||
use std::time; | ||
use std::convert; | ||
use super::Time; |
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.
submodules can already see their enclosing module's contents so this use
isn't needed.
I went ahead and rebased this on the current master and made most (all?) of the changes I suggested in the branch brian-time-type. LMK what you think. |
looks good to me! |
Thanks! This was all committed, with some clean-ups, as: edbbb81 Drop dependency on the time crate; use Thanks again! |
This is
briansmith/SystemTime
with an extra commit on top to keep the crateno_std
, as desired in issue #9.This introduces a new non-default feature
use_std
. Personally I could take it or leave it; it saves only a few lines of code in consuming crates.