| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/sync/util/nigori.h" | 5 #include "chrome/browser/sync/util/nigori.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 // Corrput the ciphertext by changing one of its bytes. | 91 // Corrput the ciphertext by changing one of its bytes. |
| 92 encrypted[browser_sync::Nigori::kIvSize + 10] = | 92 encrypted[browser_sync::Nigori::kIvSize + 10] = |
| 93 (encrypted[browser_sync::Nigori::kIvSize + 10] == 'a' ? 'b' : 'a'); | 93 (encrypted[browser_sync::Nigori::kIvSize + 10] == 'a' ? 'b' : 'a'); |
| 94 | 94 |
| 95 std::string decrypted; | 95 std::string decrypted; |
| 96 EXPECT_FALSE(nigori.Decrypt(encrypted, &decrypted)); | 96 EXPECT_FALSE(nigori.Decrypt(encrypted, &decrypted)); |
| 97 | 97 |
| 98 EXPECT_NE(plaintext, decrypted); | 98 EXPECT_NE(plaintext, decrypted); |
| 99 } | 99 } |
| 100 |
| 101 TEST(NigoriTest, Permute) { |
| 102 browser_sync::Nigori nigori("example.com"); |
| 103 EXPECT_TRUE(nigori.Init("username", "password")); |
| 104 |
| 105 std::string permuted; |
| 106 EXPECT_TRUE(nigori.Permute(browser_sync::Nigori::Password, "test name", |
| 107 &permuted)); |
| 108 |
| 109 std::string expected = |
| 110 "prewwdJj2PrGDczvmsHJEE5ndcCyVze8sY9kD5hjY/Tm" |
| 111 "c5kOjXFK7zB3Ss4LlHjEDirMu+vh85JwHOnGrMVe+g=="; |
| 112 EXPECT_EQ(expected, permuted); |
| 113 } |
| 114 |
| 115 TEST(NigoriTest, Decrypt) { |
| 116 browser_sync::Nigori nigori("example.com"); |
| 117 EXPECT_TRUE(nigori.Init("username", "password")); |
| 118 |
| 119 std::string encrypted = |
| 120 "e7+JyS6ibj6F5qqvpseukNRTZ+oBpu5iuv2VYjOfrH1dNiFLNf7Ov0" |
| 121 "kx/zicKFn0lJcbG1UmkNWqIuR4x+quDNVuLaZGbrJPhrJuj7cokCM="; |
| 122 |
| 123 std::string plaintext; |
| 124 EXPECT_TRUE(nigori.Decrypt(encrypted, &plaintext)); |
| 125 |
| 126 std::string expected("test, test, 1, 2, 3"); |
| 127 EXPECT_EQ(expected, plaintext); |
| 128 } |
| OLD | NEW |