diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-14 23:16:00 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-14 23:16:00 +0000 |
commit | 390d037275969c9902f3df0d475c3dd83b980a59 (patch) | |
tree | 3a20a5b21c770ef72c3eb8e4a84b2a7205b9e0b5 | |
parent | 7f18e945afc5c93ad9937e8f36990ce46a0f4170 (diff) | |
download | chromium_src-390d037275969c9902f3df0d475c3dd83b980a59.zip chromium_src-390d037275969c9902f3df0d475c3dd83b980a59.tar.gz chromium_src-390d037275969c9902f3df0d475c3dd83b980a59.tar.bz2 |
Revert 114499 - Simplify PRTimeToBaseTime implementation, add BaseTimeToPRTime.
BUG=107047
TEST=crypto_unittests
Review URL: http://codereview.chromium.org/8894023
TBR=mattm@chromium.org
Review URL: http://codereview.chromium.org/8913018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114524 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | crypto/crypto.gyp | 2 | ||||
-rw-r--r-- | crypto/nss_util.cc | 22 | ||||
-rw-r--r-- | crypto/nss_util.h | 4 | ||||
-rw-r--r-- | crypto/nss_util_unittest.cc | 40 |
4 files changed, 16 insertions, 52 deletions
diff --git a/crypto/crypto.gyp b/crypto/crypto.gyp index 2b76403..fb3935f 100644 --- a/crypto/crypto.gyp +++ b/crypto/crypto.gyp @@ -209,7 +209,6 @@ 'ec_private_key_unittest.cc', 'encryptor_unittest.cc', 'hmac_unittest.cc', - 'nss_util_unittest.cc', 'p224_unittest.cc', 'p224_spake_unittest.cc', 'rsa_private_key_unittest.cc', @@ -254,7 +253,6 @@ }], [ 'use_openssl==1', { 'sources!': [ - 'nss_util_unittest.cc', 'openpgp_symmetric_encryption_unittest.cc', 'rsa_private_key_nss_unittest.cc', ], diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc index 2540c0c..53602c3 100644 --- a/crypto/nss_util.cc +++ b/crypto/nss_util.cc @@ -769,13 +769,23 @@ SymmetricKey* GetSupplementalUserKey() { } #endif // defined(OS_CHROMEOS) +// TODO(port): Implement this more simply. We can convert by subtracting an +// offset (the difference between NSPR's and base::Time's epochs). base::Time PRTimeToBaseTime(PRTime prtime) { - return base::Time::FromInternalValue( - prtime + base::Time::UnixEpoch().ToInternalValue()); -} - -PRTime BaseTimeToPRTime(base::Time time) { - return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue(); + PRExplodedTime prxtime; + PR_ExplodeTime(prtime, PR_GMTParameters, &prxtime); + + base::Time::Exploded exploded; + exploded.year = prxtime.tm_year; + exploded.month = prxtime.tm_month + 1; + exploded.day_of_week = prxtime.tm_wday; + exploded.day_of_month = prxtime.tm_mday; + exploded.hour = prxtime.tm_hour; + exploded.minute = prxtime.tm_min; + exploded.second = prxtime.tm_sec; + exploded.millisecond = prxtime.tm_usec / 1000; + + return base::Time::FromUTCExploded(exploded); } PK11SlotInfo* GetPublicNSSKeySlot() { diff --git a/crypto/nss_util.h b/crypto/nss_util.h index 746691d..a617224 100644 --- a/crypto/nss_util.h +++ b/crypto/nss_util.h @@ -149,10 +149,6 @@ CRYPTO_EXPORT SymmetricKey* GetSupplementalUserKey(); // We use a int64 instead of PRTime here to avoid depending on NSPR headers. CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); -// Convert a base::Time object into a PRTime value. -// We use a int64 instead of PRTime here to avoid depending on NSPR headers. -CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); - #if defined(USE_NSS) // Exposed for unittests only. |path| should be an existing directory under // which the DB files will be placed. |description| is a user-visible name for diff --git a/crypto/nss_util_unittest.cc b/crypto/nss_util_unittest.cc deleted file mode 100644 index cc24b61..0000000 --- a/crypto/nss_util_unittest.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "crypto/nss_util.h" - -#include <prtime.h> - -#include "base/time.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace crypto { - -TEST(NSSUtilTest, PRTimeConversion) { - EXPECT_EQ(base::Time::UnixEpoch(), PRTimeToBaseTime(0)); - EXPECT_EQ(0, BaseTimeToPRTime(base::Time::UnixEpoch())); - - PRExplodedTime prxtime; - prxtime.tm_params.tp_gmt_offset = 0; - prxtime.tm_params.tp_dst_offset = 0; - base::Time::Exploded exploded; - prxtime.tm_year = exploded.year = 2011; - exploded.month = 12; - prxtime.tm_month = 11; - prxtime.tm_wday = exploded.day_of_week = 0; // Should be unusued. - prxtime.tm_mday = exploded.day_of_month = 10; - prxtime.tm_hour = exploded.hour = 2; - prxtime.tm_min = exploded.minute = 52; - prxtime.tm_sec = exploded.second = 19; - exploded.millisecond = 342; - prxtime.tm_usec = 342000; - - PRTime pr_time = PR_ImplodeTime(&prxtime); - base::Time base_time = base::Time::FromUTCExploded(exploded); - - EXPECT_EQ(base_time, PRTimeToBaseTime(pr_time)); - EXPECT_EQ(pr_time, BaseTimeToPRTime(base_time)); -} - -} // namespace crypto |