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

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

Issue 1558018: Implements support for PBKDF2-based key derivation, random key generation, an... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Style fixup Created 10 years, 8 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 | « base/crypto/encryptor.h ('k') | base/crypto/encryptor_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) || defined(OS_MACOSX) 14 TEST(EncryptorTest, EncryptDecrypt) {
15 #define MAYBE(name) name
16 #else
17 #define MAYBE(name) DISABLED_ ## name
18 #endif
19
20 TEST(EncryptorTest, MAYBE(EncryptDecrypt)) {
21 scoped_ptr<base::SymmetricKey> key(base::SymmetricKey::DeriveKeyFromPassword( 15 scoped_ptr<base::SymmetricKey> key(base::SymmetricKey::DeriveKeyFromPassword(
22 base::SymmetricKey::AES, "password", "saltiest", 1000, 256)); 16 base::SymmetricKey::AES, "password", "saltiest", 1000, 256));
23 EXPECT_TRUE(NULL != key.get()); 17 EXPECT_TRUE(NULL != key.get());
24 18
25 base::Encryptor encryptor; 19 base::Encryptor encryptor;
26 // The IV must be exactly as long a the cipher block size. 20 // The IV must be exactly as long a the cipher block size.
27 std::string iv("the iv: 16 bytes"); 21 std::string iv("the iv: 16 bytes");
28 EXPECT_TRUE(encryptor.Init(key.get(), base::Encryptor::CBC, iv)); 22 EXPECT_TRUE(encryptor.Init(key.get(), base::Encryptor::CBC, iv));
29 23
30 std::string plaintext("this is the plaintext"); 24 std::string plaintext("this is the plaintext");
31 std::string ciphertext; 25 std::string ciphertext;
32 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); 26 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext));
33 27
34 EXPECT_LT(0U, ciphertext.size()); 28 EXPECT_LT(0U, ciphertext.size());
35 29
36 std::string decypted; 30 std::string decypted;
37 EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); 31 EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted));
38 32
39 EXPECT_EQ(plaintext, decypted); 33 EXPECT_EQ(plaintext, decypted);
40 } 34 }
OLDNEW
« no previous file with comments | « base/crypto/encryptor.h ('k') | base/crypto/encryptor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698