Skip to content
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

Fixing datetime tuf specification #839

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Conversation

SequeI
Copy link

@SequeI SequeI commented Nov 12, 2024

Issue #, if available:
Currently when using tuftool create or tuftool update, the created metadata will have nanoseconds within the metadata datetime.
As you can see in the official tuf specifications here, ISO 8601 is the current standard by which it is "YYYY-MM-DDTHH:MM:SSZ".

Description of changes:
Right now, the concatenated datetime object results in an unwanted nanosecond ending so in this PR any nanosecond result on the datetime object is set to 0, effectively rounding it to the nearest second so it is in line with the tuf specs.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jpculp
Copy link
Contributor

jpculp commented Nov 15, 2024

Hi @SequeI, thank you for your contribution. We'll take a look!

@cbgbt
Copy link
Contributor

cbgbt commented Dec 10, 2024

Thanks for your contribution!

You're right, we do need to constrain the timestamp outputs here to match the spec. Rather than constrain our datetime parsing, I'd prefer if we could instead focus on controlling the serialization.

It seems like there's an example in the serde documentation for customizing the date format from chrono. We could implement a serializer and then ensure that serializable structs with inner timestamps use the correct serialization, but that seems like it would be easy to make a mistake.

Another way we could approach this would be to create a newtype wrapper around DateTime<Utc> with the desired Serialize implementation. Here's an example of what I mean implemented in the Rust playground:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=65a2c0f9ec2691bfad3daf04d9d39640

I've never tried it, but I wonder if this would combine nicely with the clippy disallowed_types lint to ensure that we prefer the wrapper instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants