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

Side by Side Diff: base/crypto/encryptor_unittest.cc

Issue 1347002: Add Mac implementations of new SymmetricKey and Encryptor classes. (Closed)
Patch Set: Responding to feedback Created 10 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
OLDNEW
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 "base/crypto/encryptor.h" 5 #include "base/crypto/encryptor.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/crypto/symmetric_key.h" 9 #include "base/crypto/symmetric_key.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 #if defined(USE_NSS) 14 #if defined(USE_NSS) || defined(OS_MACOSX)
15 #define MAYBE(name) name 15 #define MAYBE(name) name
16 #else 16 #else
17 #define MAYBE(name) DISABLED_ ## name 17 #define MAYBE(name) DISABLED_ ## name
18 #endif 18 #endif
19 19
20 TEST(EncryptorTest, MAYBE(EncryptDecrypt)) { 20 TEST(EncryptorTest, MAYBE(EncryptDecrypt)) {
21 scoped_ptr<base::SymmetricKey> key(base::SymmetricKey::DeriveKeyFromPassword( 21 scoped_ptr<base::SymmetricKey> key(base::SymmetricKey::DeriveKeyFromPassword(
22 base::SymmetricKey::AES, "password", "salt", 1000, 32)); 22 base::SymmetricKey::AES, "password", "saltiest", 1000, 256));
23 EXPECT_TRUE(NULL != key.get()); 23 EXPECT_TRUE(NULL != key.get());
24 24
25 base::Encryptor encryptor; 25 base::Encryptor encryptor;
26 // The IV must be exactly as long a the cipher block size. 26 // The IV must be exactly as long a the cipher block size.
27 std::string iv("the iv: 16 bytes"); 27 std::string iv("the iv: 16 bytes");
28 EXPECT_TRUE(encryptor.Init(key.release(), base::Encryptor::CBC, iv)); 28 EXPECT_TRUE(encryptor.Init(key.release(), base::Encryptor::CBC, iv));
29 29
30 std::string plaintext("this is the plaintext"); 30 std::string plaintext("this is the plaintext");
31 std::string ciphertext; 31 std::string ciphertext;
32 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); 32 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext));
33 33
34 EXPECT_LT(0U, ciphertext.size()); 34 EXPECT_LT(0U, ciphertext.size());
35 35
36 std::string decypted; 36 std::string decypted;
37 EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); 37 EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted));
38 38
39 EXPECT_EQ(plaintext, decypted); 39 EXPECT_EQ(plaintext, decypted);
40 } 40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698