]>
git.saurik.com Git - apple/security.git/blob - CertTool/cdsaUtils/timeStr.cpp
0ce02bb551e0fbba447bc7df0f7ec4590a403427
8 * Given a string containing either a UTC-style or "generalized time"
9 * time string, convert to a struct tm (in GMT/UTC). Returns nonzero on
12 int appTimeStringToTm(
23 if((str
== NULL
) || (len
== 0) || (tmp
== NULL
)) {
27 /* tolerate NULL terminated or not */
28 if(str
[len
- 1] == '\0') {
32 case UTC_TIME_STRLEN
: // 2-digit year, not Y2K compliant
35 case GENERALIZED_TIME_STRLEN
: // 4-digit year
38 default: // unknown format
44 /* check that all characters except last are digits */
45 for(i
=0; i
<(len
- 1); i
++) {
46 if ( !(isdigit(cp
[i
])) ) {
51 /* check last character is a 'Z' */
52 if(cp
[len
- 1] != 'Z' ) {
72 * 0 <= year < 50 : assume century 21
73 * 50 <= year < 70 : illegal per PKIX
74 * 70 < year <= 99 : assume century 20
87 /* by definition - tm_year is year - 1900 */
88 tmp
->tm_year
= x
- 1900;
95 /* in the string, months are from 1 to 12 */
96 if((x
> 12) || (x
<= 0)) {
99 /* in a tm, 0 to 11 */
107 /* 1..31 in both formats */
108 if((x
> 31) || (x
<= 0)) {
118 if((x
> 23) || (x
< 0)) {
128 if((x
> 59) || (x
< 0)) {
138 if((x
> 59) || (x
< 0)) {