diff options
author | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 06:05:27 +0000 |
---|---|---|
committer | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 06:05:27 +0000 |
commit | 5852edc1b6eab234b9e048c41dd0d664ae7fc747 (patch) | |
tree | 9e5d8eb4833b76cdb11e66fc3607689e0f5e0122 /chrome/browser/sync/util/crypto_helpers.cc | |
parent | f6059e37f8b8ac335ce18a189a13e702974a1c7e (diff) | |
download | chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.zip chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.tar.gz chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.tar.bz2 |
Initial commit of sync engine code to browser/sync.
The code is not built on any platform yet. That will arrive
as a subsequent checkin.
This is an implementation of the interface exposed earlier
through syncapi.h. It is the client side of a sync
protocol that lets users sync their browser data
(currently, just bookmarks) with their Google Account.
Table of contents:
browser/sync/
protocol - The protocol definition, and
other definitions necessary to connect to
the service.
syncable/ - defines a data model for syncable objects,
and provides a sqlite-based backing store
for this model.
engine/ - includes the core sync logic, including commiting
changes to the server, downloading changes from
the server, resolving conflicts, other parts of
the sync algorithm.
engine/net - parts of the sync engine focused on the
business of talking to the server. Some of
this is binds a generic "server connection"
interface to a concrete implementation
provided by Chromium.
notifier - the part of the syncer focused on the business
of sending and receiving xmpp notifications.
Notifications are used instead of polling to
achieve very low latency change propagation.
util - not necessarily sync specific utility code. Much
of this is scaffolding which should either be
replaced by, or merged with, the utility code
in base/.
BUG=none
TEST=this code includes its own suite of unit tests.
Review URL: http://codereview.chromium.org/194065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/util/crypto_helpers.cc')
-rw-r--r-- | chrome/browser/sync/util/crypto_helpers.cc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/chrome/browser/sync/util/crypto_helpers.cc b/chrome/browser/sync/util/crypto_helpers.cc new file mode 100644 index 0000000..c84bfaf --- /dev/null +++ b/chrome/browser/sync/util/crypto_helpers.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2009 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/sync/util/crypto_helpers.h" + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/format_macros.h" +#include "base/logging.h" +#include "base/rand_util.h" +#include "base/string_util.h" + +using std::string; +using std::vector; + +MD5Calculator::MD5Calculator() { + MD5Init(&context_); +} + +void MD5Calculator::AddData(const unsigned char* data, int length) { + CHECK(bin_digest_.empty()); + MD5Update(&context_, data, length); +} + +void MD5Calculator::CalcDigest() { + if (bin_digest_.empty()) { + MD5Digest digest; + MD5Final(&digest, &context_); + bin_digest_.assign(digest.a, digest.a + arraysize(digest.a)); + } +} + +vector<uint8> MD5Calculator::GetDigest() { + CalcDigest(); + return bin_digest_; +} + +PathString MD5Calculator::GetHexDigest() { + CalcDigest(); + string hex = HexEncode(reinterpret_cast<char*>(&bin_digest_.front()), + bin_digest_.size()); + StringToLowerASCII(&hex); + return PathString(hex.begin(), hex.end()); +} + +void GetRandomBytes(char* output, int output_length) { + for (int i = 0; i < output_length; i++) { + // TODO(chron): replace this with something less stupid. + output[i] = static_cast<char>(base::RandUint64()); + } +} + +string Generate128BitRandomHexString() { + int64 chunk1 = static_cast<int64>(base::RandUint64()); + int64 chunk2 = static_cast<int64>(base::RandUint64()); + + return StringPrintf("%016" PRId64 "x%016" PRId64 "x", + chunk1, chunk2); +} |