| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "crypto/ec_private_key.h" | 6 #include "crypto/ec_private_key.h" |
| 7 #include "crypto/openssl_util.h" | 7 #include "crypto/openssl_util.h" |
| 8 #include "crypto/scoped_openssl_types.h" | 8 #include "crypto/scoped_openssl_types.h" |
| 9 #include "net/cert/x509_util.h" | 9 #include "net/cert/x509_util.h" |
| 10 #include "net/cert/x509_util_openssl.h" | 10 #include "net/cert/x509_util_openssl.h" |
| 11 #include "net/ssl/scoped_openssl_types.h" | 11 #include "net/ssl/scoped_openssl_types.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 TEST(X509UtilOpenSSLTest, IsSupportedValidityRange) { | 16 TEST(X509UtilOpenSSLTest, IsSupportedValidityRange) { |
| 17 base::Time now = base::Time::Now(); | 17 base::Time now = base::Time::Now(); |
| 18 EXPECT_TRUE(x509_util::IsSupportedValidityRange(now, now)); | 18 EXPECT_TRUE(x509_util::IsSupportedValidityRange(now, now)); |
| 19 EXPECT_FALSE(x509_util::IsSupportedValidityRange( | 19 EXPECT_FALSE(x509_util::IsSupportedValidityRange( |
| 20 now, now - base::TimeDelta::FromSeconds(1))); | 20 now, now - base::TimeDelta::FromSeconds(1))); |
| 21 | 21 |
| 22 // See x509_util_openssl.cc to see how these were computed. | 22 // See x509_util_openssl.cc to see how these were computed. |
| 23 const int64 kDaysFromYear0001ToUnixEpoch = 719162; | 23 const int64_t kDaysFromYear0001ToUnixEpoch = 719162; |
| 24 const int64 kDaysFromUnixEpochToYear10000 = 2932896 + 1; | 24 const int64_t kDaysFromUnixEpochToYear10000 = 2932896 + 1; |
| 25 | 25 |
| 26 // When computing too_old / too_late, add one day to account for | 26 // When computing too_old / too_late, add one day to account for |
| 27 // possible leap seconds. | 27 // possible leap seconds. |
| 28 base::Time too_old = base::Time::UnixEpoch() - | 28 base::Time too_old = base::Time::UnixEpoch() - |
| 29 base::TimeDelta::FromDays(kDaysFromYear0001ToUnixEpoch + 1); | 29 base::TimeDelta::FromDays(kDaysFromYear0001ToUnixEpoch + 1); |
| 30 | 30 |
| 31 base::Time too_late = base::Time::UnixEpoch() + | 31 base::Time too_late = base::Time::UnixEpoch() + |
| 32 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000 + 1); | 32 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000 + 1); |
| 33 | 33 |
| 34 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, too_old)); | 34 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, too_old)); |
| 35 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, now)); | 35 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, now)); |
| 36 | 36 |
| 37 EXPECT_FALSE(x509_util::IsSupportedValidityRange(now, too_late)); | 37 EXPECT_FALSE(x509_util::IsSupportedValidityRange(now, too_late)); |
| 38 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_late, too_late)); | 38 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_late, too_late)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace net | 41 } // namespace net |
| OLD | NEW |