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

Add GeneralizedTime #492

Merged
merged 15 commits into from
Nov 3, 2024

Conversation

DarkaMaul
Copy link
Contributor

Fixes #491

/cc @woodruffw

Signed-off-by: Alexis <alexis.challande@trailofbits.com>
src/types.rs Outdated Show resolved Hide resolved
Signed-off-by: Alexis <alexis.challande@trailofbits.com>
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
@DarkaMaul
Copy link
Contributor Author

I've used a nanoseconds precision for the fractional time ( from 1 to 10^9) but I can't find a reference saying that the value is bounded (or not).

From T-REC-X.680-202102-I!!PDF-E.pdf, it seems the precision is arbitrary

2) a string representing the time of day to an accuracy of one hour, one minute, one second, or
fractions of a second (to any degree of accuracy), using either comma or full stop as the decimal sign (as
specified in ISO 8601, 4.2.2.2 and 4.2.2.3 – Basic format); optionally followed by:

And the X.690-0207 spec only says that the second is required:

11.7.2 The seconds element shall always be present. 

However, the Quick ASN1 reference uses a 3 digit representation for the floating part.

What would be the best option here?

@alex
Copy link
Owner

alex commented Oct 25, 2024 via email

Signed-off-by: Alexis <alexis.challande@trailofbits.com>
Signed-off-by: Alexis <alexis.challande@trailofbits.com>
Signed-off-by: Alexis <alexis.challande@trailofbits.com>
@DarkaMaul
Copy link
Contributor Author

Grumble. Nanosecond precision is fine. But this also means the prohibition on leading 0s is wrong, right?

I think this one is still valid as it stems from :

11.7.3 The fractional-seconds elements, if present, shall omit all trailing zeros; if the elements correspond to 0, they
shall be wholly omitted, and the decimal point element also shall be omitted. 

@alex
Copy link
Owner

alex commented Oct 25, 2024 via email

@DarkaMaul
Copy link
Contributor Author

Trailing and leading zeros are the opposite :-)
😮‍💨 Yes indeed - let me update the PR ...

Signed-off-by: Alexis <alexis.challande@trailofbits.com>
src/types.rs Outdated Show resolved Hide resolved
Signed-off-by: Alexis <alexis.challande@trailofbits.com>
@alex
Copy link
Owner

alex commented Oct 25, 2024

Apologies in advance, but For simplicity of review, I think pulling the "rename GeneralizedTime" into its own PR probably is the best path.

@DarkaMaul DarkaMaul force-pushed the dm/add-generalized-time-fractional branch from ace99a6 to 031bfb4 Compare October 25, 2024 15:35
@DarkaMaul DarkaMaul changed the title Add GeneralizedTimeFractional Add GeneralizedTime Oct 29, 2024
README.md Outdated Show resolved Hide resolved
Signed-off-by: William Woodruff <william@trailofbits.com>
@@ -914,7 +915,8 @@ fn push_four_digits(dest: &mut WriteBuf, val: u16) -> WriteResult {
}

/// A structure representing a (UTC timezone) date and time.
/// Wrapped by `UtcTime` and `X509GeneralizedTime`.
/// Wrapped by `UtcTime` and `X509GeneralizedTime` and used in
/// `GeneralizedTime`.
#[derive(Debug, Clone, PartialEq, Hash, Eq, PartialOrd)]
pub struct DateTime {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should DateTime just have an optional nanoseconds field?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, missed this earlier. I don't have a super strong opinion -- I think @DarkaMaul put the nanos on GeneralizedTime since UTCTime has no fractional time support at all, so having it on the top-level DateTime used by both seems (slightly) off.

OTOH having it on GeneralizedTime also seems slightly off, since it's now (DateTime, nanos). So I'm happy to move if you'd prefer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, let's get the docs right on the generalized tiem strcut and that'll be good enough. (See my other comment)

src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
Signed-off-by: William Woodruff <william@trailofbits.com>
Keeps us in a stack buf.

Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Copy link
Owner

@alex alex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last open question

@@ -914,7 +915,8 @@ fn push_four_digits(dest: &mut WriteBuf, val: u16) -> WriteResult {
}

/// A structure representing a (UTC timezone) date and time.
/// Wrapped by `UtcTime` and `X509GeneralizedTime`.
/// Wrapped by `UtcTime` and `X509GeneralizedTime` and used in
/// `GeneralizedTime`.
#[derive(Debug, Clone, PartialEq, Hash, Eq, PartialOrd)]
pub struct DateTime {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts here?

src/types.rs Outdated
@@ -1088,6 +1089,125 @@ impl SimpleAsn1Writable for X509GeneralizedTime {
}
}

/// Used for parsing and writing ASN.1 `GENERALIZED TIME` values accepting
/// fractional seconds value.
/// See https://github.com/alex/rust-asn1/issues/491 for discussion.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be updated to just describe the type, not reference an issue about how things used to be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -914,7 +915,8 @@ fn push_four_digits(dest: &mut WriteBuf, val: u16) -> WriteResult {
}

/// A structure representing a (UTC timezone) date and time.
/// Wrapped by `UtcTime` and `X509GeneralizedTime`.
/// Wrapped by `UtcTime` and `X509GeneralizedTime` and used in
/// `GeneralizedTime`.
#[derive(Debug, Clone, PartialEq, Hash, Eq, PartialOrd)]
pub struct DateTime {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, let's get the docs right on the generalized tiem strcut and that'll be good enough. (See my other comment)

src/types.rs Outdated Show resolved Hide resolved
@alex alex merged commit e37fa65 into alex:main Nov 3, 2024
12 checks passed
@woodruffw woodruffw deleted the dm/add-generalized-time-fractional branch November 3, 2024 20:41
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.

GeneralizedTime: support for fractional seconds?
3 participants