diff options
-rw-r--r-- | security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.c | 179 | ||||
-rw-r--r-- | security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.h | 2 |
2 files changed, 46 insertions, 135 deletions
diff --git a/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.c b/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.c index 48bf75663..2d9a61723 100644 --- a/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.c +++ b/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.c @@ -71,19 +71,10 @@ pkix_pl_Date_GetPRTime( PRTime *pPRTime, void *plContext) { - SECStatus rv = SECFailure; - PKIX_ENTER(DATE, "PKIX_PL_Date_GetPRTime"); PKIX_NULLCHECK_TWO(date, pPRTime); - PKIX_DATE_DEBUG("\t\tCalling DER_DecodeTimeChoice).\n"); - rv = DER_DecodeTimeChoice(pPRTime, &date->nssTime); - - if (rv == SECFailure) { - PKIX_ERROR(PKIX_DERDECODETIMECHOICEFAILED); - } - -cleanup: + *pPRTime = date->nssTime; PKIX_RETURN(DATE); } @@ -114,20 +105,11 @@ pkix_pl_Date_CreateFromPRTime( PKIX_PL_Date **pDate, void *plContext) { - SECItem nssTime = { 0, NULL, 0 }; - SECStatus rv = SECFailure; PKIX_PL_Date *date = NULL; PKIX_ENTER(DATE, "PKIX_PL_Date_CreateFromPRTime"); PKIX_NULLCHECK_ONE(pDate); - PKIX_DATE_DEBUG("\t\tCalling DER_EncodeTimeChoice).\n"); - rv = DER_EncodeTimeChoice(NULL, &nssTime, prtime); - - if (rv == SECFailure) { - PKIX_ERROR(PKIX_DERENCODETIMECHOICEFAILED); - } - /* create a PKIX_PL_Date object */ PKIX_CHECK(PKIX_PL_Object_Alloc (PKIX_DATE_TYPE, @@ -135,18 +117,10 @@ pkix_pl_Date_CreateFromPRTime( (PKIX_PL_Object **)&date, plContext), PKIX_COULDNOTCREATEOBJECT); - /* populate the nssTime field */ - date->nssTime = nssTime; - + date->nssTime = prtime; *pDate = date; - cleanup: - - if (PKIX_ERROR_RECEIVED){ - PR_Free(nssTime.data); - } - PKIX_RETURN(DATE); } @@ -211,7 +185,6 @@ pkix_pl_Date_ToString_Helper( PKIX_STRINGCREATEFAILED); cleanup: - PR_Free(asciiDate); PKIX_RETURN(DATE); @@ -227,20 +200,12 @@ pkix_pl_Date_Destroy( PKIX_PL_Object *object, void *plContext) { - PKIX_PL_Date *date = NULL; - PKIX_ENTER(DATE, "pkix_pl_Date_Destroy"); PKIX_NULLCHECK_ONE(object); PKIX_CHECK(pkix_CheckType(object, PKIX_DATE_TYPE, plContext), PKIX_OBJECTNOTDATE); - - date = (PKIX_PL_Date *)object; - - PR_Free(date->nssTime.data); - cleanup: - PKIX_RETURN(DATE); } @@ -254,10 +219,9 @@ pkix_pl_Date_ToString( PKIX_PL_String **pString, void *plContext) { - PKIX_PL_String *dateString = NULL; PKIX_PL_Date *date = NULL; - SECItem *nssTime = NULL; - char *asciiDate = NULL; + SECItem nssTime = {siBuffer, NULL, 0}; + SECStatus rv; PKIX_ENTER(DATE, "pkix_pl_Date_toString"); PKIX_NULLCHECK_TWO(object, pString); @@ -266,18 +230,17 @@ pkix_pl_Date_ToString( PKIX_OBJECTNOTDATE); date = (PKIX_PL_Date *)object; - - nssTime = &date->nssTime; - + rv = DER_EncodeTimeChoice(NULL, &nssTime, date->nssTime); + if (rv == SECFailure) { + PKIX_ERROR(PKIX_DERENCODETIMECHOICEFAILED); + } PKIX_CHECK(pkix_pl_Date_ToString_Helper - (nssTime, &dateString, plContext), + (&nssTime, pString, plContext), PKIX_DATETOSTRINGHELPERFAILED); - - *pString = dateString; - cleanup: - - PKIX_FREE(asciiDate); + if (nssTime.data) { + SECITEM_FreeItem(&nssTime, PR_FALSE); + } PKIX_RETURN(DATE); } @@ -293,7 +256,6 @@ pkix_pl_Date_Hashcode( void *plContext) { PKIX_PL_Date *date = NULL; - SECItem *nssTime = NULL; PKIX_UInt32 dateHash; PKIX_ENTER(DATE, "pkix_pl_Date_Hashcode"); @@ -304,12 +266,9 @@ pkix_pl_Date_Hashcode( date = (PKIX_PL_Date *)object; - nssTime = &date->nssTime; - - PKIX_CHECK - (pkix_hash - ((const unsigned char *)nssTime->data, - nssTime->len, + PKIX_CHECK(pkix_hash + ((const unsigned char *)&date->nssTime, + sizeof(date->nssTime), &dateHash, plContext), PKIX_HASHFAILED); @@ -333,8 +292,8 @@ pkix_pl_Date_Comparator( PKIX_Int32 *pResult, void *plContext) { - SECItem *firstTime = NULL; - SECItem *secondTime = NULL; + PRTime firstTime; + PRTime secondTime; SECComparison cmpResult; PKIX_ENTER(DATE, "pkix_pl_Date_Comparator"); @@ -344,11 +303,15 @@ pkix_pl_Date_Comparator( (firstObject, secondObject, PKIX_DATE_TYPE, plContext), PKIX_ARGUMENTSNOTDATES); - firstTime = &((PKIX_PL_Date *)firstObject)->nssTime; - secondTime = &((PKIX_PL_Date *)secondObject)->nssTime; + firstTime = ((PKIX_PL_Date *)firstObject)->nssTime; + secondTime = ((PKIX_PL_Date *)secondObject)->nssTime; - PKIX_DATE_DEBUG("\t\tCalling SECITEM_CompareItem).\n"); - cmpResult = SECITEM_CompareItem(firstTime, secondTime); + if (firstTime == secondTime) + cmpResult = SECEqual; + else if (firstTime < secondTime) + cmpResult = SECLessThan; + else + cmpResult = SECGreaterThan; *pResult = cmpResult; @@ -368,14 +331,6 @@ pkix_pl_Date_Equals( PKIX_Boolean *pResult, void *plContext) { - - /* note: pkix_pl_Date can only represent UTCTime,not GeneralizedTime */ - - SECItem *firstTime = NULL; - SECItem *secondTime = NULL; - PKIX_UInt32 secondType; - SECComparison cmpResult; - PKIX_ENTER(DATE, "pkix_pl_Date_Equals"); PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); @@ -392,24 +347,14 @@ pkix_pl_Date_Equals( goto cleanup; } - /* - * If secondObject isn't a Date, we don't throw an error. - * We simply return a Boolean result of FALSE - */ *pResult = PKIX_FALSE; - PKIX_CHECK(PKIX_PL_Object_GetType - (secondObject, &secondType, plContext), - PKIX_COULDNOTGETTYPEOFSECONDARGUMENT); - if (secondType != PKIX_DATE_TYPE) goto cleanup; - - firstTime = &((PKIX_PL_Date *)firstObject)->nssTime; - secondTime = &((PKIX_PL_Date *)secondObject)->nssTime; - - PKIX_DATE_DEBUG("\t\tCalling SECITEM_CompareItem).\n"); - cmpResult = SECITEM_CompareItem(firstTime, secondTime); - - *pResult = (cmpResult == SECEqual); - + pkixErrorResult = + pkix_pl_Date_Comparator(firstObject, secondObject, + pResult, plContext); + if (pkixErrorResult) { + PKIX_DECREF(pkixErrorResult); + } + cleanup: PKIX_RETURN(DATE); @@ -430,21 +375,18 @@ PKIX_Error * pkix_pl_Date_RegisterSelf(void *plContext) { extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; - pkix_ClassTable_Entry entry; - - PKIX_ENTER(DATE, "pkix_pl_Date_RegisterSelf"); + pkix_ClassTable_Entry* entry = &systemClasses[PKIX_DATE_TYPE]; - entry.description = "Date"; - entry.objCounter = 0; - entry.typeObjectSize = sizeof(PKIX_PL_Date); - entry.destructor = pkix_pl_Date_Destroy; - entry.equalsFunction = pkix_pl_Date_Equals; - entry.hashcodeFunction = pkix_pl_Date_Hashcode; - entry.toStringFunction = pkix_pl_Date_ToString; - entry.comparator = pkix_pl_Date_Comparator; - entry.duplicateFunction = pkix_duplicateImmutable; + PKIX_ENTER(CRLCHECKER, "pkix_CrlDp_RegisterSelf"); - systemClasses[PKIX_DATE_TYPE] = entry; + entry->description = "Date"; + entry->typeObjectSize = sizeof(PKIX_PL_Date); + entry->destructor = pkix_pl_Date_Destroy; + entry->equalsFunction = pkix_pl_Date_Equals; + entry->hashcodeFunction = pkix_pl_Date_Hashcode; + entry->toStringFunction = pkix_pl_Date_ToString; + entry->comparator = pkix_pl_Date_Comparator; + entry->duplicateFunction = pkix_duplicateImmutable; PKIX_RETURN(DATE); } @@ -463,7 +405,6 @@ PKIX_PL_Date_Create_UTCTime( PKIX_PL_Date *date = NULL; char *asciiString = NULL; PKIX_UInt32 escAsciiLength; - SECItem nssTime; SECStatus rv; PRTime time; @@ -491,12 +432,6 @@ PKIX_PL_Date_Create_UTCTime( } } - PKIX_DATE_DEBUG("\t\tCalling DER_TimeToUTCTime).\n"); - rv = DER_TimeToUTCTime(&nssTime, time); - if (rv != SECSuccess){ - PKIX_ERROR(PKIX_DERTIMETOUTCTIMEFAILED); - } - /* create a PKIX_PL_Date object */ PKIX_CHECK(PKIX_PL_Object_Alloc (PKIX_DATE_TYPE, @@ -506,18 +441,12 @@ PKIX_PL_Date_Create_UTCTime( PKIX_COULDNOTCREATEOBJECT); /* populate the nssTime field */ - date->nssTime = nssTime; - + date->nssTime = time; *pDate = date; cleanup: - PKIX_FREE(asciiString); - if (PKIX_ERROR_RECEIVED){ - PR_Free(nssTime.data); - } - PKIX_RETURN(DATE); } @@ -532,24 +461,12 @@ PKIX_PL_Date_Create_CurrentOffBySeconds( void *plContext) { PKIX_PL_Date *date = NULL; - SECItem nssTime; - SECStatus rv; PRTime time; PKIX_ENTER(DATE, "PKIX_PL_Date_Create_CurrentOffBySeconds"); PKIX_NULLCHECK_ONE(pDate); - PKIX_DATE_DEBUG("\t\tCalling PR_Now).\n"); - time = PR_Now(); - - time += (secondsOffset * PR_USEC_PER_SEC); - - PKIX_DATE_DEBUG("\t\tCalling DER_TimeToUTCTime).\n"); - rv = DER_TimeToUTCTime(&nssTime, time); - if (rv != SECSuccess){ - PKIX_ERROR(PKIX_DERTIMETOUTCTIMEFAILED); - } - + time = PR_Now() + PR_SecondsToInterval(secondsOffset); /* create a PKIX_PL_Date object */ PKIX_CHECK(PKIX_PL_Object_Alloc (PKIX_DATE_TYPE, @@ -559,16 +476,10 @@ PKIX_PL_Date_Create_CurrentOffBySeconds( PKIX_COULDNOTCREATEOBJECT); /* populate the nssTime field */ - date->nssTime = nssTime; - + date->nssTime = time; *pDate = date; cleanup: - - if (PKIX_ERROR_RECEIVED){ - PR_Free(nssTime.data); - } - PKIX_RETURN(DATE); } diff --git a/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.h b/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.h index 4211f506b..feb49dcfb 100644 --- a/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.h +++ b/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_date.h @@ -51,7 +51,7 @@ extern "C" { #endif struct PKIX_PL_DateStruct{ - SECItem nssTime; + PRTime nssTime; }; /* see source file for function documentation */ |