michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "secder.h" michael@0: #include "secerr.h" michael@0: michael@0: int main() michael@0: { michael@0: SECItem badTime; michael@0: PRTime prtime; michael@0: SECStatus rv; michael@0: int error; michael@0: PRBool failed = PR_FALSE; michael@0: michael@0: /* A UTCTime string with an embedded null. */ michael@0: badTime.type = siBuffer; michael@0: badTime.data = (unsigned char *)"091219000000Z\0junkjunkjunkjunkjunkjunk"; michael@0: badTime.len = 38; michael@0: rv = DER_UTCTimeToTime(&prtime, &badTime); michael@0: if (rv == SECSuccess) { michael@0: fprintf(stderr, "DER_UTCTimeToTime should have failed but " michael@0: "succeeded\n"); michael@0: failed = PR_TRUE; michael@0: } else { michael@0: error = PORT_GetError(); michael@0: if (error != SEC_ERROR_INVALID_TIME) { michael@0: fprintf(stderr, "DER_UTCTimeToTime failed with error %d, " michael@0: "expected error %d\n", error, SEC_ERROR_INVALID_TIME); michael@0: failed = PR_TRUE; michael@0: } michael@0: } michael@0: michael@0: /* A UTCTime string with junk after a valid date/time. */ michael@0: badTime.type = siBuffer; michael@0: badTime.data = (unsigned char *)"091219000000Zjunk"; michael@0: badTime.len = 17; michael@0: rv = DER_UTCTimeToTime(&prtime, &badTime); michael@0: if (rv == SECSuccess) { michael@0: fprintf(stderr, "DER_UTCTimeToTime should have failed but " michael@0: "succeeded\n"); michael@0: failed = PR_TRUE; michael@0: } else { michael@0: error = PORT_GetError(); michael@0: if (error != SEC_ERROR_INVALID_TIME) { michael@0: fprintf(stderr, "DER_UTCTimeToTime failed with error %d, " michael@0: "expected error %d\n", error, SEC_ERROR_INVALID_TIME); michael@0: failed = PR_TRUE; michael@0: } michael@0: } michael@0: michael@0: /* A GeneralizedTime string with an embedded null. */ michael@0: badTime.type = siBuffer; michael@0: badTime.data = (unsigned char *)"20091219000000Z\0junkjunkjunkjunkjunkjunk"; michael@0: badTime.len = 40; michael@0: rv = DER_GeneralizedTimeToTime(&prtime, &badTime); michael@0: if (rv == SECSuccess) { michael@0: fprintf(stderr, "DER_GeneralizedTimeToTime should have failed but " michael@0: "succeeded\n"); michael@0: failed = PR_TRUE; michael@0: } else { michael@0: error = PORT_GetError(); michael@0: if (error != SEC_ERROR_INVALID_TIME) { michael@0: fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, " michael@0: "expected error %d\n", error, SEC_ERROR_INVALID_TIME); michael@0: failed = PR_TRUE; michael@0: } michael@0: } michael@0: michael@0: /* A GeneralizedTime string with junk after a valid date/time. */ michael@0: badTime.type = siBuffer; michael@0: badTime.data = (unsigned char *)"20091219000000Zjunk"; michael@0: badTime.len = 19; michael@0: rv = DER_GeneralizedTimeToTime(&prtime, &badTime); michael@0: if (rv == SECSuccess) { michael@0: fprintf(stderr, "DER_GeneralizedTimeToTime should have failed but " michael@0: "succeeded\n"); michael@0: failed = PR_TRUE; michael@0: } else { michael@0: error = PORT_GetError(); michael@0: if (error != SEC_ERROR_INVALID_TIME) { michael@0: fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, " michael@0: "expected error %d\n", error, SEC_ERROR_INVALID_TIME); michael@0: failed = PR_TRUE; michael@0: } michael@0: } michael@0: michael@0: if (failed) { michael@0: fprintf(stderr, "FAIL\n"); michael@0: return 1; michael@0: } michael@0: printf("PASS\n"); michael@0: return 0; michael@0: }