Skip to content

rust: reconsider dependency on time crate in public APIs #74

@valkum

Description

@valkum

The time crate had multiple issues in the past and thus was replaced by other crates in numerous codebases.
Now there is chrono with at least the same amount of downloads in the last 90 days and jiff as a rather new crate.

Until the Rust ecosystem consolidates on one major crate again, the best way is to support at least the two big ones or stick to std::time.
time is currently only used in MessageSigner::generate_signature_headers_content to get the value for created and expires.

created can simply be replaced by (this is taken from time::UtcDateTime::now()):

match system_time.duration_since(SystemTime::UNIX_EPOCH) {
            Ok(duration) => Self::UNIX_EPOCH + duration,
            Err(err) => Self::UNIX_EPOCH - err.duration(),
        }

jiff goes so far and says it would be ok to panic if the local time is too far in the past or future. But that completely depends on whether this crate should be panic-free or not.

The expires argument for MessageSigner::generate_signature_headers_content should just be std::time::Duration. I don't think using time::Duration has any benefit here. The major difference is that time::duration can be negative, which does not make sense for the expires argument, at least if the docs of MessageSigner::generate_signature_headers_content are taken as granted.

This will keep the API surface clean of any particular date & time crate for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions