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

Fix #340: Parse ASN1_TIME to struct tm #3378

Closed
wants to merge 1 commit into from

Conversation

tmshort
Copy link
Contributor

@tmshort tmshort commented May 3, 2017

This works with ASN1_UTCTIME and ASN1_GENERALIZED_TIME

Checklist
  • documentation is added or updated
  • tests are added or updated

@tmshort
Copy link
Contributor Author

tmshort commented May 3, 2017

Fixes #340

@@ -130,7 +130,7 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str)
return 1;
}

static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t)
int ASN1_TIME_to_tm(struct tm *tm, const ASN1_TIME *t)
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering what order the params should be in. Recently we have tended to always put the primary object first with the function name also starting with the primary object name. But here the ASN1_TIME type comes second.

Copy link
Contributor

Choose a reason for hiding this comment

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

i agree it should be flipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup; I just un-static-fied the exiting function, but I agree, the arguments should be reversed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will note that ASN1_TIME_print() is an anomaly (not suggesting this changes the need to reverse the arguments).

@@ -13,6 +13,7 @@ ASN1_TIME_print, ASN1_TIME_diff - ASN.1 Time functions
int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
int ASN1_TIME_check(const ASN1_TIME *t);
int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
int ASN1_TIME_to_tm(struct tm *tm, const ASN1_TIME *t);
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be added to the NAME section too.

Copy link
Contributor

Choose a reason for hiding this comment

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

find-doc-nits is your friend. :)

@@ -123,6 +129,9 @@ otherwise.
ASN1_TIME_print() returns 1 if the time is successfully printed out and 0 if
an error occurred (I/O error or invalid time format).

ASN1_TIME_to_tm() returns 1 if the time is successfully parsed and 0 if an
error occured (invalid time format).

ASN1_TIME_diff() returns 1 for success and 0 for failure. It can fail if the
pass ASN1_TIME structure has invalid syntax for example.

Copy link
Member

Choose a reason for hiding this comment

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

Please can we add a HISTORY section and update the COPYRIGHT date.

@@ -130,7 +130,7 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str)
return 1;
}

static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t)
int ASN1_TIME_to_tm(struct tm *tm, const ASN1_TIME *t)
Copy link
Contributor

Choose a reason for hiding this comment

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

i agree it should be flipped.

@@ -152,9 +152,9 @@ int ASN1_TIME_diff(int *pday, int *psec,
const ASN1_TIME *from, const ASN1_TIME *to)
{
struct tm tm_from, tm_to;
if (!asn1_time_to_tm(&tm_from, from))
if (!ASN1_TIME_to_tm(&tm_from, from))
Copy link
Contributor

Choose a reason for hiding this comment

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

since you're here, blank line before the declaration.

@@ -13,6 +13,7 @@ ASN1_TIME_print, ASN1_TIME_diff - ASN.1 Time functions
int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
int ASN1_TIME_check(const ASN1_TIME *t);
int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
int ASN1_TIME_to_tm(struct tm *tm, const ASN1_TIME *t);
Copy link
Contributor

Choose a reason for hiding this comment

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

find-doc-nits is your friend. :)

@@ -42,6 +43,11 @@ format. It will be of the format MMM DD HH:MM:SS YYYY [GMT], for example
structure has invalid format it prints out "Bad time value" and returns
an error.

ASN1_TIME_to_tm() converts the time B<s> to the standard B<tm> structure.
Copy link
Contributor

Choose a reason for hiding this comment

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

prose here says as but the prototype above says t

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed ASN1_TIME_to_tm() everywhere to s to make it consistent with other ASN1_TIME functions.

@tmshort
Copy link
Contributor Author

tmshort commented May 8, 2017

Fixed everything, I believe.

@tmshort
Copy link
Contributor Author

tmshort commented May 22, 2017

rebase ping

Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Approved subject to the minor nit being fixed.

@@ -42,6 +43,11 @@ format. It will be of the format MMM DD HH:MM:SS YYYY [GMT], for example
structure has invalid format it prints out "Bad time value" and returns
an error.

ASN1_TIME_to_tm() converts the time B<s> to the standard B<tm> structure.
If B<s> is NULL, the the current time is converted. The output time is GMT.
Copy link
Member

Choose a reason for hiding this comment

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

nit: then the

@tmshort
Copy link
Contributor Author

tmshort commented May 22, 2017

Committed a doc tweak, which can be squashed.

@tmshort
Copy link
Contributor Author

tmshort commented Jun 6, 2017

ping?

@mattcaswell
Copy link
Member

@richsalz this needs your plus one

Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

should we memset the 'struct tm' since there might be fields we don't know about? but approved.

@tmshort
Copy link
Contributor Author

tmshort commented Jun 7, 2017

should we memset the 'struct tm' since there might be fields we don't know about? but approved.

The documentation explicitly states what fields are filled in, but yeah, I think it's a good idea.

Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

@mattcaswell you can just merge if you approve of this.

This works with ASN1_UTCTIME and ASN1_GENERALIZED_TIME
@tmshort
Copy link
Contributor Author

tmshort commented Jun 8, 2017

Fixed the merge conflict...

@InfoHunter InfoHunter mentioned this pull request Jun 8, 2017
2 tasks
@mattcaswell
Copy link
Member

Pushed. Thanks.

@mattcaswell mattcaswell closed this Jun 8, 2017
levitte pushed a commit that referenced this pull request Jun 8, 2017
This works with ASN1_UTCTIME and ASN1_GENERALIZED_TIME

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #3378)
@tmshort tmshort deleted the master-get-tm branch June 8, 2017 12:40
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.

None yet

3 participants