summaryrefslogtreecommitdiff
path: root/nss/lib/util/dertime.c
diff options
context:
space:
mode:
Diffstat (limited to 'nss/lib/util/dertime.c')
-rw-r--r--nss/lib/util/dertime.c164
1 files changed, 82 insertions, 82 deletions
diff --git a/nss/lib/util/dertime.c b/nss/lib/util/dertime.c
index 3a27827..f58fc18 100644
--- a/nss/lib/util/dertime.c
+++ b/nss/lib/util/dertime.c
@@ -12,39 +12,40 @@
#define LODIGIT(v) (((v) % 10) + '0')
#define ISDIGIT(dig) (((dig) >= '0') && ((dig) <= '9'))
-#define CAPTURE(var,p,label) \
-{ \
- if (!ISDIGIT((p)[0]) || !ISDIGIT((p)[1])) goto label; \
- (var) = ((p)[0] - '0') * 10 + ((p)[1] - '0'); \
- p += 2; \
-}
+#define CAPTURE(var, p, label) \
+ { \
+ if (!ISDIGIT((p)[0]) || !ISDIGIT((p)[1])) \
+ goto label; \
+ (var) = ((p)[0] - '0') * 10 + ((p)[1] - '0'); \
+ p += 2; \
+ }
-static const PRTime January1st1 = (PRTime) LL_INIT(0xff234001U, 0x00d44000U);
-static const PRTime January1st1950 = (PRTime) LL_INIT(0xfffdc1f8U, 0x793da000U);
-static const PRTime January1st2050 = LL_INIT(0x0008f81e, 0x1b098000);
-static const PRTime January1st10000 = LL_INIT(0x0384440c, 0xcc736000);
+static const PRTime January1st1 = PR_INT64(0xff23400100d44000);
+static const PRTime January1st1950 = PR_INT64(0xfffdc1f8793da000);
+static const PRTime January1st2050 = PR_INT64(0x0008f81e1b098000);
+static const PRTime January1st10000 = PR_INT64(0x0384440ccc736000);
/* gmttime must contains UTC time in micro-seconds unit */
SECStatus
-DER_TimeToUTCTimeArena(PLArenaPool* arenaOpt, SECItem *dst, PRTime gmttime)
+DER_TimeToUTCTimeArena(PLArenaPool *arenaOpt, SECItem *dst, PRTime gmttime)
{
PRExplodedTime printableTime;
unsigned char *d;
- if ( (gmttime < January1st1950) || (gmttime >= January1st2050) ) {
+ if ((gmttime < January1st1950) || (gmttime >= January1st2050)) {
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return SECFailure;
}
dst->len = 13;
if (arenaOpt) {
- dst->data = d = (unsigned char*) PORT_ArenaAlloc(arenaOpt, dst->len);
+ dst->data = d = (unsigned char *)PORT_ArenaAlloc(arenaOpt, dst->len);
} else {
- dst->data = d = (unsigned char*) PORT_Alloc(dst->len);
+ dst->data = d = (unsigned char *)PORT_Alloc(dst->len);
}
dst->type = siUTCTime;
if (!d) {
- return SECFailure;
+ return SECFailure;
}
/* Convert a PRTime to a printable format. */
@@ -53,9 +54,9 @@ DER_TimeToUTCTimeArena(PLArenaPool* arenaOpt, SECItem *dst, PRTime gmttime)
/* The month in UTC time is base one */
printableTime.tm_month++;
- /* remove the century since it's added to the tm_year by the
+ /* remove the century since it's added to the tm_year by the
PR_ExplodeTime routine, but is not needed for UTC time */
- printableTime.tm_year %= 100;
+ printableTime.tm_year %= 100;
d[0] = HIDIGIT(printableTime.tm_year);
d[1] = LODIGIT(printableTime.tm_year);
@@ -80,15 +81,15 @@ DER_TimeToUTCTime(SECItem *dst, PRTime gmttime)
}
static SECStatus /* forward */
-der_TimeStringToTime(PRTime *dst, const char *string, int generalized,
- const char **endptr);
+ der_TimeStringToTime(PRTime *dst, const char *string, int generalized,
+ const char **endptr);
#define GEN_STRING 2 /* TimeString is a GeneralizedTime */
#define UTC_STRING 0 /* TimeString is a UTCTime */
/* The caller of DER_AsciiToItem MUST ENSURE that either
** a) "string" points to a null-terminated ASCII string, or
-** b) "string" points to a buffer containing a valid UTCTime,
+** b) "string" points to a buffer containing a valid UTCTime,
** whether null terminated or not, or
** c) "string" contains at least 19 characters, with or without null char.
** otherwise, this function may UMR and/or crash.
@@ -103,9 +104,9 @@ DER_AsciiToTime(PRTime *dst, const char *string)
SECStatus
DER_UTCTimeToTime(PRTime *dst, const SECItem *time)
{
- /* Minimum valid UTCTime is yymmddhhmmZ which is 11 bytes.
+ /* Minimum valid UTCTime is yymmddhhmmZ which is 11 bytes.
** Maximum valid UTCTime is yymmddhhmmss+0000 which is 17 bytes.
- ** 20 should be large enough for all valid encoded times.
+ ** 20 should be large enough for all valid encoded times.
*/
unsigned int i;
char localBuf[20];
@@ -113,23 +114,23 @@ DER_UTCTimeToTime(PRTime *dst, const SECItem *time)
SECStatus rv;
if (!time || !time->data || time->len < 11 || time->len > 17) {
- PORT_SetError(SEC_ERROR_INVALID_TIME);
- return SECFailure;
+ PORT_SetError(SEC_ERROR_INVALID_TIME);
+ return SECFailure;
}
for (i = 0; i < time->len; i++) {
- if (time->data[i] == '\0') {
- PORT_SetError(SEC_ERROR_INVALID_TIME);
- return SECFailure;
- }
- localBuf[i] = time->data[i];
+ if (time->data[i] == '\0') {
+ PORT_SetError(SEC_ERROR_INVALID_TIME);
+ return SECFailure;
+ }
+ localBuf[i] = time->data[i];
}
localBuf[i] = '\0';
rv = der_TimeStringToTime(dst, localBuf, UTC_STRING, &end);
if (rv == SECSuccess && *end != '\0') {
- PORT_SetError(SEC_ERROR_INVALID_TIME);
- return SECFailure;
+ PORT_SetError(SEC_ERROR_INVALID_TIME);
+ return SECFailure;
}
return rv;
}
@@ -140,27 +141,27 @@ DER_UTCTimeToTime(PRTime *dst, const SECItem *time)
should only be used for certifiate validities after the
year 2049. Otherwise, UTC time should be used. This routine
does not check this case, since it can be used to encode
- certificate extension, which does not have this restriction.
+ certificate extension, which does not have this restriction.
*/
SECStatus
-DER_TimeToGeneralizedTimeArena(PLArenaPool* arenaOpt, SECItem *dst, PRTime gmttime)
+DER_TimeToGeneralizedTimeArena(PLArenaPool *arenaOpt, SECItem *dst, PRTime gmttime)
{
PRExplodedTime printableTime;
unsigned char *d;
- if ( (gmttime<January1st1) || (gmttime>=January1st10000) ) {
+ if ((gmttime < January1st1) || (gmttime >= January1st10000)) {
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return SECFailure;
}
dst->len = 15;
if (arenaOpt) {
- dst->data = d = (unsigned char*) PORT_ArenaAlloc(arenaOpt, dst->len);
+ dst->data = d = (unsigned char *)PORT_ArenaAlloc(arenaOpt, dst->len);
} else {
- dst->data = d = (unsigned char*) PORT_Alloc(dst->len);
+ dst->data = d = (unsigned char *)PORT_Alloc(dst->len);
}
dst->type = siGeneralizedTime;
if (!d) {
- return SECFailure;
+ return SECFailure;
}
/* Convert a PRTime to a printable format. */
@@ -169,7 +170,7 @@ DER_TimeToGeneralizedTimeArena(PLArenaPool* arenaOpt, SECItem *dst, PRTime gmtti
/* The month in Generalized time is base one */
printableTime.tm_month++;
- d[0] = (printableTime.tm_year /1000) + '0';
+ d[0] = (printableTime.tm_year / 1000) + '0';
d[1] = ((printableTime.tm_year % 1000) / 100) + '0';
d[2] = ((printableTime.tm_year % 100) / 10) + '0';
d[3] = (printableTime.tm_year % 10) + '0';
@@ -193,13 +194,12 @@ DER_TimeToGeneralizedTime(SECItem *dst, PRTime gmttime)
return DER_TimeToGeneralizedTimeArena(NULL, dst, gmttime);
}
-
SECStatus
DER_GeneralizedTimeToTime(PRTime *dst, const SECItem *time)
{
/* Minimum valid GeneralizedTime is ccyymmddhhmmZ which is 13 bytes.
** Maximum valid GeneralizedTime is ccyymmddhhmmss+0000 which is 19 bytes.
- ** 20 should be large enough for all valid encoded times.
+ ** 20 should be large enough for all valid encoded times.
*/
unsigned int i;
char localBuf[20];
@@ -207,23 +207,23 @@ DER_GeneralizedTimeToTime(PRTime *dst, const SECItem *time)
SECStatus rv;
if (!time || !time->data || time->len < 13 || time->len > 19) {
- PORT_SetError(SEC_ERROR_INVALID_TIME);
- return SECFailure;
+ PORT_SetError(SEC_ERROR_INVALID_TIME);
+ return SECFailure;
}
for (i = 0; i < time->len; i++) {
- if (time->data[i] == '\0') {
- PORT_SetError(SEC_ERROR_INVALID_TIME);
- return SECFailure;
- }
- localBuf[i] = time->data[i];
+ if (time->data[i] == '\0') {
+ PORT_SetError(SEC_ERROR_INVALID_TIME);
+ return SECFailure;
+ }
+ localBuf[i] = time->data[i];
}
localBuf[i] = '\0';
rv = der_TimeStringToTime(dst, localBuf, GEN_STRING, &end);
if (rv == SECSuccess && *end != '\0') {
- PORT_SetError(SEC_ERROR_INVALID_TIME);
- return SECFailure;
+ PORT_SetError(SEC_ERROR_INVALID_TIME);
+ return SECFailure;
}
return rv;
}
@@ -238,64 +238,64 @@ der_TimeStringToTime(PRTime *dst, const char *string, int generalized,
char signum;
if (string == NULL || dst == NULL) {
- PORT_SetError(SEC_ERROR_INVALID_ARGS);
- return SECFailure;
+ PORT_SetError(SEC_ERROR_INVALID_ARGS);
+ return SECFailure;
}
/* Verify time is formatted properly and capture information */
memset(&genTime, 0, sizeof genTime);
if (generalized == UTC_STRING) {
- CAPTURE(genTime.tm_year, string, loser);
- century = (genTime.tm_year < 50) ? 20 : 19;
+ CAPTURE(genTime.tm_year, string, loser);
+ century = (genTime.tm_year < 50) ? 20 : 19;
} else {
- CAPTURE(century, string, loser);
- CAPTURE(genTime.tm_year, string, loser);
+ CAPTURE(century, string, loser);
+ CAPTURE(genTime.tm_year, string, loser);
}
genTime.tm_year += century * 100;
CAPTURE(genTime.tm_month, string, loser);
- if ((genTime.tm_month == 0) || (genTime.tm_month > 12))
- goto loser;
+ if ((genTime.tm_month == 0) || (genTime.tm_month > 12))
+ goto loser;
/* NSPR month base is 0 */
--genTime.tm_month;
-
+
CAPTURE(genTime.tm_mday, string, loser);
- if ((genTime.tm_mday == 0) || (genTime.tm_mday > 31))
- goto loser;
-
+ if ((genTime.tm_mday == 0) || (genTime.tm_mday > 31))
+ goto loser;
+
CAPTURE(genTime.tm_hour, string, loser);
- if (genTime.tm_hour > 23)
- goto loser;
-
+ if (genTime.tm_hour > 23)
+ goto loser;
+
CAPTURE(genTime.tm_min, string, loser);
- if (genTime.tm_min > 59)
- goto loser;
-
+ if (genTime.tm_min > 59)
+ goto loser;
+
if (ISDIGIT(string[0])) {
- CAPTURE(genTime.tm_sec, string, loser);
- if (genTime.tm_sec > 59)
- goto loser;
+ CAPTURE(genTime.tm_sec, string, loser);
+ if (genTime.tm_sec > 59)
+ goto loser;
}
signum = *string++;
if (signum == '+' || signum == '-') {
- CAPTURE(hourOff, string, loser);
- if (hourOff > 23)
- goto loser;
- CAPTURE(minOff, string, loser);
- if (minOff > 59)
- goto loser;
- if (signum == '-') {
- hourOff = -hourOff;
- minOff = -minOff;
- }
+ CAPTURE(hourOff, string, loser);
+ if (hourOff > 23)
+ goto loser;
+ CAPTURE(minOff, string, loser);
+ if (minOff > 59)
+ goto loser;
+ if (signum == '-') {
+ hourOff = -hourOff;
+ minOff = -minOff;
+ }
} else if (signum != 'Z') {
- goto loser;
+ goto loser;
}
if (endptr)
- *endptr = string;
+ *endptr = string;
/* Convert the GMT offset to seconds and save it in genTime
* for the implode time call.