-
Notifications
You must be signed in to change notification settings - Fork 18
Use std::time API instead of u64s for timestamp and expiry time #8
Conversation
a70f7c9
to
47ade71
Compare
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.
At a high level I think its nice to use the std::time API just for convenience though I don't think it really helps safety given that we have to restrict the timestamp + expiry delta to make sure they dont overflow anyway (and much better to do it during deserialize than hope the user remembers to avoid the unwrap() either way).
I'd argue that it removes possible logic errors where you accidentally pass a completely unrelated integer into a function expecting an expiry time etc. It makes you think twice if the integer you have is actually a duration (and if so with which unit) and should be converted accordingly. |
I guess I'll just merge now, I think I addressed all of your comments. And btw thx for making me implement fuzz tests (not PR ready yet), they already found a round trip/serialization bug in this PR 😃 (fixed by now) |
Using dedicated time structs should make the API less error prone and easier to use right. Since we don't want to pull in unnecessary Dependencies I didn't use
chrono
.But
std::time
unfortunately misses a way to do time calculations (likeSystemTime + Duration
) in a non-panicking way (see rust-lang/rust#55527). So I had to make some wild guesses about our potential target platforms and their internal representations of time which can't be statically asserted yet unfortunately. That means we end up with some really ugly heuristics that try to keep people from using the library in ways that would expose them to DoS attacks by overflowing the time calculations.I nonetheless think that it's the right thing to improve the API in that way. With some luck my rust-lang PR will end up in the debian stable rust release in the next decade 😭 but it's ok as long as that will happen before 2037 😄
Since @TheBlueMatt is the only user of this library I know of: what do you think about that change. I think that was the last short-term API-breaking change, so I'd really like to publish a
0.1.0
soon.