Exemplo n.º 1
0
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. 
    */
    unsigned int i;
    char localBuf[20];
    const char *end = NULL;
    SECStatus rv;

    if (!time || !time->data || time->len < 13 || time->len > 19) {
	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];
    }
    localBuf[i] = '\0';

    rv = der_TimeStringToTime(dst, localBuf, GEN_STRING, &end);
    if (rv == SECSuccess && *end != '\0') {
	PORT_SetError(SEC_ERROR_INVALID_TIME);
	return SECFailure;
    }
    return rv;
}
Exemplo n.º 2
0
SECStatus
DER_GeneralizedTimeToTime(int64 *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. 
    */
    int  len;
    char localBuf[20];

    if (!time || !time->data || time->len < 13) {
	PORT_SetError(SEC_ERROR_INVALID_TIME);
	return SECFailure;
    }

    len = PR_MIN(time->len, sizeof localBuf);
    memcpy(localBuf, time->data, len);
    while (len < sizeof localBuf) {
        localBuf[len++] = '\0';
    }

    return der_TimeStringToTime(dst, localBuf, GEN_STRING);
}
Exemplo n.º 3
0
/* 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, 
**     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.
** It suffices to ensure that the input "string" is at least 17 bytes long.
*/
SECStatus
DER_AsciiToTime(int64 *dst, const char *string)
{
    return der_TimeStringToTime(dst, string, UTC_STRING);
}
Exemplo n.º 4
0
/* 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, 
**     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.
** It suffices to ensure that the input "string" is at least 17 bytes long.
*/
SECStatus
DER_AsciiToTime(PRTime *dst, const char *string)
{
    return der_TimeStringToTime(dst, string, UTC_STRING, NULL);
}