Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: chrome/browser/profile_resetter/jtl_foundation.cc

Issue 533183002: Revert "Eliminate all code related to the AutomaticProfileResetter." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profile_resetter/jtl_foundation.cc
diff --git a/chrome/browser/profile_resetter/jtl_foundation.cc b/chrome/browser/profile_resetter/jtl_foundation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0739040cc5e0d2abd1e50ac0082bafb75ef445d6
--- /dev/null
+++ b/chrome/browser/profile_resetter/jtl_foundation.cc
@@ -0,0 +1,48 @@
+// Copyright 2013 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 "chrome/browser/profile_resetter/jtl_foundation.h"
+
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
+
+namespace jtl_foundation {
+
+Hasher::Hasher(const std::string& seed) : hmac_(crypto::HMAC::SHA256) {
+ if (!hmac_.Init(seed))
+ NOTREACHED();
+}
+
+Hasher::~Hasher() {}
+
+std::string Hasher::GetHash(const std::string& input) const {
+ if (cached_hashes_.find(input) == cached_hashes_.end()) {
+ // Calculate value.
+ unsigned char digest[kHashSizeInBytes];
+ if (!hmac_.Sign(input, digest, arraysize(digest))) {
+ NOTREACHED();
+ return std::string();
+ }
+ // Instead of using the full SHA256, we only use the hex encoding of the
+ // first 16 bytes.
+ cached_hashes_[input] = base::HexEncode(digest, kHashSizeInBytes / 2);
+ DCHECK_EQ(kHashSizeInBytes, cached_hashes_[input].size());
+ }
+ return cached_hashes_[input];
+}
+
+// static
+bool Hasher::IsHash(const std::string& maybe_hash) {
+ if (maybe_hash.size() != kHashSizeInBytes)
+ return false;
+ for (std::string::const_iterator it = maybe_hash.begin();
+ it != maybe_hash.end(); ++it) {
+ if (!IsHexDigit(*it))
+ return false;
+ }
+ return true;
+}
+
+} // namespace jtl_foundation
« no previous file with comments | « chrome/browser/profile_resetter/jtl_foundation.h ('k') | chrome/browser/profile_resetter/jtl_instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698