]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/time_offset_test.c
2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* time_t/offset (+/-XXXX) tests for ASN1 and X509 */
16 #include <openssl/asn1.h>
17 #include <openssl/x509.h>
19 #include "internal/nelem.h"
28 /**********************************************************************
34 static TESTDATA tests
[] = {
35 { "20001201000000Z", 0, V_ASN1_GENERALIZEDTIME
},
36 { "20001201010000+0100", 0, V_ASN1_GENERALIZEDTIME
},
37 { "20001201050000+0500", 0, V_ASN1_GENERALIZEDTIME
},
38 { "20001130230000-0100", 0, V_ASN1_GENERALIZEDTIME
},
39 { "20001130190000-0500", 0, V_ASN1_GENERALIZEDTIME
},
40 { "20001130190001-0500", 1, V_ASN1_GENERALIZEDTIME
}, /* +1 second */
41 { "20001130185959-0500", -1, V_ASN1_GENERALIZEDTIME
}, /* -1 second */
42 { "001201000000Z", 0, V_ASN1_UTCTIME
},
43 { "001201010000+0100", 0, V_ASN1_UTCTIME
},
44 { "001201050000+0500", 0, V_ASN1_UTCTIME
},
45 { "001130230000-0100", 0, V_ASN1_UTCTIME
},
46 { "001130190000-0500", 0, V_ASN1_UTCTIME
},
47 { "001201000000-0000", 0, V_ASN1_UTCTIME
},
48 { "001201000001-0000", 1, V_ASN1_UTCTIME
}, /* +1 second */
49 { "001130235959-0000", -1, V_ASN1_UTCTIME
}, /* -1 second */
50 { "20001201000000+0000", 0, V_ASN1_GENERALIZEDTIME
},
51 { "20001201000000+0100", -1, V_ASN1_GENERALIZEDTIME
},
52 { "001201000000+0100", -1, V_ASN1_UTCTIME
},
53 { "20001201000000-0100", 1, V_ASN1_GENERALIZEDTIME
},
54 { "001201000000-0100", 1, V_ASN1_UTCTIME
},
55 { "20001201123400+1234", 0, V_ASN1_GENERALIZEDTIME
},
56 { "20001130112600-1234", 0, V_ASN1_GENERALIZEDTIME
},
59 static time_t the_time
= 975628800;
60 static ASN1_TIME the_asn1_time
= {
62 V_ASN1_GENERALIZEDTIME
,
63 (unsigned char*)"20001201000000Z",
67 static int test_offset(int idx
)
70 const TESTDATA
*testdata
= &tests
[idx
];
74 at
.data
= (unsigned char*)testdata
->data
;
75 at
.length
= strlen(testdata
->data
);
76 at
.type
= testdata
->type
;
79 if (!TEST_true(ASN1_TIME_diff(&day
, &sec
, &the_asn1_time
, &at
))) {
80 TEST_info("ASN1_TIME_diff() failed for %s\n", at
.data
);
94 if (!TEST_int_eq(testdata
->time_result
, ret
)) {
95 TEST_info("ASN1_TIME_diff() test failed for %s day=%d sec=%d\n", at
.data
, day
, sec
);
99 ret
= ASN1_TIME_cmp_time_t(&at
, the_time
);
101 if (!TEST_int_eq(testdata
->time_result
, ret
)) {
102 TEST_info("ASN1_UTCTIME_cmp_time_t() test failed for %s\n", at
.data
);
109 int setup_tests(void)
111 ADD_ALL_TESTS(test_offset
, OSSL_NELEM(tests
));