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 "sync/util/nigori.h" | 5 #include "sync/util/nigori.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <sstream> | 9 #include <sstream> |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/base64.h" | 12 #include "base/base64.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
13 #include "base/sys_byteorder.h" | 15 #include "base/sys_byteorder.h" |
14 #include "crypto/encryptor.h" | 16 #include "crypto/encryptor.h" |
15 #include "crypto/hmac.h" | 17 #include "crypto/hmac.h" |
16 #include "crypto/random.h" | 18 #include "crypto/random.h" |
17 #include "crypto/symmetric_key.h" | 19 #include "crypto/symmetric_key.h" |
18 | 20 |
19 using base::Base64Encode; | 21 using base::Base64Encode; |
20 using base::Base64Decode; | 22 using base::Base64Decode; |
21 using crypto::Encryptor; | 23 using crypto::Encryptor; |
22 using crypto::HMAC; | 24 using crypto::HMAC; |
23 using crypto::SymmetricKey; | 25 using crypto::SymmetricKey; |
24 | 26 |
25 namespace syncer { | 27 namespace syncer { |
26 | 28 |
27 // NigoriStream simplifies the concatenation operation of the Nigori protocol. | 29 // NigoriStream simplifies the concatenation operation of the Nigori protocol. |
28 class NigoriStream { | 30 class NigoriStream { |
29 public: | 31 public: |
30 // Append the big-endian representation of the length of |value| with 32 bits, | 32 // Append the big-endian representation of the length of |value| with 32 bits, |
31 // followed by |value| itself to the stream. | 33 // followed by |value| itself to the stream. |
32 NigoriStream& operator<<(const std::string& value) { | 34 NigoriStream& operator<<(const std::string& value) { |
33 uint32 size = base::HostToNet32(value.size()); | 35 uint32_t size = base::HostToNet32(value.size()); |
34 | 36 |
35 stream_.write(reinterpret_cast<char*>(&size), sizeof(uint32)); | 37 stream_.write(reinterpret_cast<char*>(&size), sizeof(uint32_t)); |
36 stream_ << value; | 38 stream_ << value; |
37 return *this; | 39 return *this; |
38 } | 40 } |
39 | 41 |
40 // Append the big-endian representation of the length of |type| with 32 bits, | 42 // Append the big-endian representation of the length of |type| with 32 bits, |
41 // followed by the big-endian representation of the value of |type|, with 32 | 43 // followed by the big-endian representation of the value of |type|, with 32 |
42 // bits, to the stream. | 44 // bits, to the stream. |
43 NigoriStream& operator<<(const Nigori::Type type) { | 45 NigoriStream& operator<<(const Nigori::Type type) { |
44 uint32 size = base::HostToNet32(sizeof(uint32)); | 46 uint32_t size = base::HostToNet32(sizeof(uint32_t)); |
45 stream_.write(reinterpret_cast<char*>(&size), sizeof(uint32)); | 47 stream_.write(reinterpret_cast<char*>(&size), sizeof(uint32_t)); |
46 uint32 value = base::HostToNet32(type); | 48 uint32_t value = base::HostToNet32(type); |
47 stream_.write(reinterpret_cast<char*>(&value), sizeof(uint32)); | 49 stream_.write(reinterpret_cast<char*>(&value), sizeof(uint32_t)); |
48 return *this; | 50 return *this; |
49 } | 51 } |
50 | 52 |
51 std::string str() { | 53 std::string str() { |
52 return stream_.str(); | 54 return stream_.str(); |
53 } | 55 } |
54 | 56 |
55 private: | 57 private: |
56 std::ostringstream stream_; | 58 std::ostringstream stream_; |
57 }; | 59 }; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 DCHECK(user_key); | 244 DCHECK(user_key); |
243 DCHECK(encryption_key); | 245 DCHECK(encryption_key); |
244 DCHECK(mac_key); | 246 DCHECK(mac_key); |
245 | 247 |
246 return user_key_->GetRawKey(user_key) && | 248 return user_key_->GetRawKey(user_key) && |
247 encryption_key_->GetRawKey(encryption_key) && | 249 encryption_key_->GetRawKey(encryption_key) && |
248 mac_key_->GetRawKey(mac_key); | 250 mac_key_->GetRawKey(mac_key); |
249 } | 251 } |
250 | 252 |
251 } // namespace syncer | 253 } // namespace syncer |
OLD | NEW |