annotate nss/lib/util/dertime.c @ 1:247cffdc9b89

Add a pesodo config file for inlcude directories and library names
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 28 Jul 2014 13:00:06 +0200
parents 1e5118fa0cb1
children
rev   line source
0
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 /* This Source Code Form is subject to the terms of the Mozilla Public
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 #include "prtypes.h"
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 #include "prtime.h"
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 #include "secder.h"
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8 #include "prlong.h"
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 #include "secerr.h"
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11 #define HIDIGIT(v) (((v) / 10) + '0')
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #define LODIGIT(v) (((v) % 10) + '0')
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #define ISDIGIT(dig) (((dig) >= '0') && ((dig) <= '9'))
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #define CAPTURE(var,p,label) \
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 { \
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 if (!ISDIGIT((p)[0]) || !ISDIGIT((p)[1])) goto label; \
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 (var) = ((p)[0] - '0') * 10 + ((p)[1] - '0'); \
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 p += 2; \
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22 static const PRTime January1st1 = (PRTime) LL_INIT(0xff234001U, 0x00d44000U);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 static const PRTime January1st1950 = (PRTime) LL_INIT(0xfffdc1f8U, 0x793da000U);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 static const PRTime January1st2050 = LL_INIT(0x0008f81e, 0x1b098000);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 static const PRTime January1st10000 = LL_INIT(0x0384440c, 0xcc736000);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 /* gmttime must contains UTC time in micro-seconds unit */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 DER_TimeToUTCTimeArena(PLArenaPool* arenaOpt, SECItem *dst, PRTime gmttime)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 PRExplodedTime printableTime;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 unsigned char *d;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 if ( (gmttime < January1st1950) || (gmttime >= January1st2050) ) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 PORT_SetError(SEC_ERROR_INVALID_ARGS);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 dst->len = 13;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 if (arenaOpt) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 dst->data = d = (unsigned char*) PORT_ArenaAlloc(arenaOpt, dst->len);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 } else {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 dst->data = d = (unsigned char*) PORT_Alloc(dst->len);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 dst->type = siUTCTime;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 if (!d) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 /* Convert a PRTime to a printable format. */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51 PR_ExplodeTime(gmttime, PR_GMTParameters, &printableTime);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 /* The month in UTC time is base one */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 printableTime.tm_month++;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 /* remove the century since it's added to the tm_year by the
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 PR_ExplodeTime routine, but is not needed for UTC time */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 printableTime.tm_year %= 100;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 d[0] = HIDIGIT(printableTime.tm_year);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 d[1] = LODIGIT(printableTime.tm_year);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 d[2] = HIDIGIT(printableTime.tm_month);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 d[3] = LODIGIT(printableTime.tm_month);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 d[4] = HIDIGIT(printableTime.tm_mday);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 d[5] = LODIGIT(printableTime.tm_mday);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 d[6] = HIDIGIT(printableTime.tm_hour);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 d[7] = LODIGIT(printableTime.tm_hour);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 d[8] = HIDIGIT(printableTime.tm_min);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 d[9] = LODIGIT(printableTime.tm_min);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 d[10] = HIDIGIT(printableTime.tm_sec);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 d[11] = LODIGIT(printableTime.tm_sec);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 d[12] = 'Z';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 return SECSuccess;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76 SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 DER_TimeToUTCTime(SECItem *dst, PRTime gmttime)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 return DER_TimeToUTCTimeArena(NULL, dst, gmttime);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82 static SECStatus /* forward */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
83 der_TimeStringToTime(PRTime *dst, const char *string, int generalized,
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84 const char **endptr);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86 #define GEN_STRING 2 /* TimeString is a GeneralizedTime */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 #define UTC_STRING 0 /* TimeString is a UTCTime */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 /* The caller of DER_AsciiToItem MUST ENSURE that either
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90 ** a) "string" points to a null-terminated ASCII string, or
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 ** b) "string" points to a buffer containing a valid UTCTime,
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 ** whether null terminated or not, or
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 ** c) "string" contains at least 19 characters, with or without null char.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 ** otherwise, this function may UMR and/or crash.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 ** It suffices to ensure that the input "string" is at least 17 bytes long.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96 */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97 SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 DER_AsciiToTime(PRTime *dst, const char *string)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 return der_TimeStringToTime(dst, string, UTC_STRING, NULL);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103 SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
104 DER_UTCTimeToTime(PRTime *dst, const SECItem *time)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
106 /* Minimum valid UTCTime is yymmddhhmmZ which is 11 bytes.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 ** Maximum valid UTCTime is yymmddhhmmss+0000 which is 17 bytes.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 ** 20 should be large enough for all valid encoded times.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109 */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110 unsigned int i;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111 char localBuf[20];
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112 const char *end = NULL;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 SECStatus rv;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115 if (!time || !time->data || time->len < 11 || time->len > 17) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 PORT_SetError(SEC_ERROR_INVALID_TIME);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 for (i = 0; i < time->len; i++) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121 if (time->data[i] == '\0') {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 PORT_SetError(SEC_ERROR_INVALID_TIME);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 localBuf[i] = time->data[i];
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
127 localBuf[i] = '\0';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129 rv = der_TimeStringToTime(dst, localBuf, UTC_STRING, &end);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130 if (rv == SECSuccess && *end != '\0') {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 PORT_SetError(SEC_ERROR_INVALID_TIME);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
132 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
134 return rv;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 /*
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
138 gmttime must contains UTC time in micro-seconds unit.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 Note: the caller should make sure that Generalized time
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 should only be used for certifiate validities after the
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 year 2049. Otherwise, UTC time should be used. This routine
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 does not check this case, since it can be used to encode
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
143 certificate extension, which does not have this restriction.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146 DER_TimeToGeneralizedTimeArena(PLArenaPool* arenaOpt, SECItem *dst, PRTime gmttime)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 PRExplodedTime printableTime;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 unsigned char *d;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 if ( (gmttime<January1st1) || (gmttime>=January1st10000) ) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 PORT_SetError(SEC_ERROR_INVALID_ARGS);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 dst->len = 15;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 if (arenaOpt) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 dst->data = d = (unsigned char*) PORT_ArenaAlloc(arenaOpt, dst->len);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 } else {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159 dst->data = d = (unsigned char*) PORT_Alloc(dst->len);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 dst->type = siGeneralizedTime;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 if (!d) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 /* Convert a PRTime to a printable format. */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 PR_ExplodeTime(gmttime, PR_GMTParameters, &printableTime);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
168
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169 /* The month in Generalized time is base one */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 printableTime.tm_month++;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172 d[0] = (printableTime.tm_year /1000) + '0';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
173 d[1] = ((printableTime.tm_year % 1000) / 100) + '0';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
174 d[2] = ((printableTime.tm_year % 100) / 10) + '0';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
175 d[3] = (printableTime.tm_year % 10) + '0';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
176 d[4] = HIDIGIT(printableTime.tm_month);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
177 d[5] = LODIGIT(printableTime.tm_month);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
178 d[6] = HIDIGIT(printableTime.tm_mday);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
179 d[7] = LODIGIT(printableTime.tm_mday);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
180 d[8] = HIDIGIT(printableTime.tm_hour);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
181 d[9] = LODIGIT(printableTime.tm_hour);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
182 d[10] = HIDIGIT(printableTime.tm_min);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
183 d[11] = LODIGIT(printableTime.tm_min);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
184 d[12] = HIDIGIT(printableTime.tm_sec);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
185 d[13] = LODIGIT(printableTime.tm_sec);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
186 d[14] = 'Z';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
187 return SECSuccess;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
188 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
189
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
190 SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
191 DER_TimeToGeneralizedTime(SECItem *dst, PRTime gmttime)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
192 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
193 return DER_TimeToGeneralizedTimeArena(NULL, dst, gmttime);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
194 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
195
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
196
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
197 SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
198 DER_GeneralizedTimeToTime(PRTime *dst, const SECItem *time)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
199 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
200 /* Minimum valid GeneralizedTime is ccyymmddhhmmZ which is 13 bytes.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
201 ** Maximum valid GeneralizedTime is ccyymmddhhmmss+0000 which is 19 bytes.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
202 ** 20 should be large enough for all valid encoded times.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
203 */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
204 unsigned int i;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
205 char localBuf[20];
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
206 const char *end = NULL;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
207 SECStatus rv;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
208
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
209 if (!time || !time->data || time->len < 13 || time->len > 19) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
210 PORT_SetError(SEC_ERROR_INVALID_TIME);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
211 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
212 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
213
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
214 for (i = 0; i < time->len; i++) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
215 if (time->data[i] == '\0') {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
216 PORT_SetError(SEC_ERROR_INVALID_TIME);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
217 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
218 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
219 localBuf[i] = time->data[i];
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
220 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
221 localBuf[i] = '\0';
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
222
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
223 rv = der_TimeStringToTime(dst, localBuf, GEN_STRING, &end);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
224 if (rv == SECSuccess && *end != '\0') {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
225 PORT_SetError(SEC_ERROR_INVALID_TIME);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
226 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
227 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
228 return rv;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
229 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
230
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
231 static SECStatus
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
232 der_TimeStringToTime(PRTime *dst, const char *string, int generalized,
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
233 const char **endptr)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
234 {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
235 PRExplodedTime genTime;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
236 long hourOff = 0, minOff = 0;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
237 PRUint16 century;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
238 char signum;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
239
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
240 if (string == NULL || dst == NULL) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
241 PORT_SetError(SEC_ERROR_INVALID_ARGS);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
242 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
243 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
244
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
245 /* Verify time is formatted properly and capture information */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
246 memset(&genTime, 0, sizeof genTime);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
247
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
248 if (generalized == UTC_STRING) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
249 CAPTURE(genTime.tm_year, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
250 century = (genTime.tm_year < 50) ? 20 : 19;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
251 } else {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
252 CAPTURE(century, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
253 CAPTURE(genTime.tm_year, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
254 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
255 genTime.tm_year += century * 100;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
256
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
257 CAPTURE(genTime.tm_month, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
258 if ((genTime.tm_month == 0) || (genTime.tm_month > 12))
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
259 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
260
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
261 /* NSPR month base is 0 */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
262 --genTime.tm_month;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
263
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
264 CAPTURE(genTime.tm_mday, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
265 if ((genTime.tm_mday == 0) || (genTime.tm_mday > 31))
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
266 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
267
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
268 CAPTURE(genTime.tm_hour, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
269 if (genTime.tm_hour > 23)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
270 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
271
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
272 CAPTURE(genTime.tm_min, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
273 if (genTime.tm_min > 59)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
274 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
275
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
276 if (ISDIGIT(string[0])) {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
277 CAPTURE(genTime.tm_sec, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
278 if (genTime.tm_sec > 59)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
279 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
280 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
281 signum = *string++;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
282 if (signum == '+' || signum == '-') {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
283 CAPTURE(hourOff, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
284 if (hourOff > 23)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
285 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
286 CAPTURE(minOff, string, loser);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
287 if (minOff > 59)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
288 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
289 if (signum == '-') {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
290 hourOff = -hourOff;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
291 minOff = -minOff;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
292 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
293 } else if (signum != 'Z') {
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
294 goto loser;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
295 }
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
296
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
297 if (endptr)
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
298 *endptr = string;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
299
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
300 /* Convert the GMT offset to seconds and save it in genTime
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
301 * for the implode time call.
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
302 */
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
303 genTime.tm_params.tp_gmt_offset = (PRInt32)((hourOff * 60L + minOff) * 60L);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
304 *dst = PR_ImplodeTime(&genTime);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
305 return SECSuccess;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
306
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
307 loser:
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
308 PORT_SetError(SEC_ERROR_INVALID_TIME);
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
309 return SECFailure;
1e5118fa0cb1 This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
310 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)