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

Side by Side Diff: chrome/browser/sync/engine/syncapi_internal.cc

Issue 9699057: [Sync] Move 'sync' target to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Tim's comments Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/engine/syncapi_internal.h ('k') | chrome/browser/sync/engine/syncer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/engine/syncapi_internal.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/sync/util/cryptographer.h"
9 #include "sync/protocol/password_specifics.pb.h"
10 #include "sync/protocol/sync.pb.h"
11
12 using browser_sync::Cryptographer;
13
14 namespace sync_api {
15
16 sync_pb::PasswordSpecificsData* DecryptPasswordSpecifics(
17 const sync_pb::EntitySpecifics& specifics, Cryptographer* crypto) {
18 if (!specifics.has_password())
19 return NULL;
20 const sync_pb::PasswordSpecifics& password_specifics = specifics.password();
21 if (!password_specifics.has_encrypted())
22 return NULL;
23 const sync_pb::EncryptedData& encrypted = password_specifics.encrypted();
24 scoped_ptr<sync_pb::PasswordSpecificsData> data(
25 new sync_pb::PasswordSpecificsData);
26 if (!crypto->Decrypt(encrypted, data.get()))
27 return NULL;
28 return data.release();
29 }
30
31 // The list of names which are reserved for use by the server.
32 static const char* kForbiddenServerNames[] = { "", ".", ".." };
33
34 // When taking a name from the syncapi, append a space if it matches the
35 // pattern of a server-illegal name followed by zero or more spaces.
36 void SyncAPINameToServerName(const std::string& sync_api_name,
37 std::string* out) {
38 *out = sync_api_name;
39 if (IsNameServerIllegalAfterTrimming(*out))
40 out->append(" ");
41 }
42
43 // Checks whether |name| is a server-illegal name followed by zero or more space
44 // characters. The three server-illegal names are the empty string, dot, and
45 // dot-dot. Very long names (>255 bytes in UTF-8 Normalization Form C) are
46 // also illegal, but are not considered here.
47 bool IsNameServerIllegalAfterTrimming(const std::string& name) {
48 size_t untrimmed_count = name.find_last_not_of(' ') + 1;
49 for (size_t i = 0; i < arraysize(kForbiddenServerNames); ++i) {
50 if (name.compare(0, untrimmed_count, kForbiddenServerNames[i]) == 0)
51 return true;
52 }
53 return false;
54 }
55
56 // Compare the values of two EntitySpecifics, accounting for encryption.
57 bool AreSpecificsEqual(const browser_sync::Cryptographer* cryptographer,
58 const sync_pb::EntitySpecifics& left,
59 const sync_pb::EntitySpecifics& right) {
60 // Note that we can't compare encrypted strings directly as they are seeded
61 // with a random value.
62 std::string left_plaintext, right_plaintext;
63 if (left.has_encrypted()) {
64 if (!cryptographer->CanDecrypt(left.encrypted())) {
65 NOTREACHED() << "Attempting to compare undecryptable data.";
66 return false;
67 }
68 left_plaintext = cryptographer->DecryptToString(left.encrypted());
69 } else {
70 left_plaintext = left.SerializeAsString();
71 }
72 if (right.has_encrypted()) {
73 if (!cryptographer->CanDecrypt(right.encrypted())) {
74 NOTREACHED() << "Attempting to compare undecryptable data.";
75 return false;
76 }
77 right_plaintext = cryptographer->DecryptToString(right.encrypted());
78 } else {
79 right_plaintext = right.SerializeAsString();
80 }
81 if (left_plaintext == right_plaintext) {
82 return true;
83 }
84 return false;
85 }
86
87 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncapi_internal.h ('k') | chrome/browser/sync/engine/syncer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698