-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Conversation
Fixes #340 |
crypto/asn1/a_time.c
Outdated
@@ -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) |
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.
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.
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.
i agree it should be flipped.
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.
Yup; I just un-static-fied the exiting function, but I agree, the arguments should be reversed.
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.
I will note that ASN1_TIME_print() is an anomaly (not suggesting this changes the need to reverse the arguments).
doc/man3/ASN1_TIME_set.pod
Outdated
@@ -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); |
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.
Needs to be added to the NAME section too.
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.
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. | |||
|
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.
Please can we add a HISTORY section and update the COPYRIGHT date.
crypto/asn1/a_time.c
Outdated
@@ -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) |
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.
i agree it should be flipped.
crypto/asn1/a_time.c
Outdated
@@ -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)) |
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.
since you're here, blank line before the declaration.
doc/man3/ASN1_TIME_set.pod
Outdated
@@ -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); |
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.
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. |
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.
prose here says as
but the prototype above says t
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.
Changed ASN1_TIME_to_tm()
everywhere to s
to make it consistent with other ASN1_TIME functions.
Fixed everything, I believe. |
rebase ping |
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.
Approved subject to the minor nit being fixed.
doc/man3/ASN1_TIME_set.pod
Outdated
@@ -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. |
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.
nit: then the
Committed a doc tweak, which can be squashed. |
ping? |
@richsalz this needs your plus one |
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.
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. |
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.
@mattcaswell you can just merge if you approve of this.
This works with ASN1_UTCTIME and ASN1_GENERALIZED_TIME
Fixed the merge conflict... |
Pushed. Thanks. |
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)
This works with ASN1_UTCTIME and ASN1_GENERALIZED_TIME
Checklist