| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "crypto/encryptor.h" | 5 #include "crypto/encryptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 crypto::Encryptor encryptor; | 274 crypto::Encryptor encryptor; |
| 275 // The IV must be exactly as long a the cipher block size. | 275 // The IV must be exactly as long a the cipher block size. |
| 276 EXPECT_EQ(16U, iv.size()); | 276 EXPECT_EQ(16U, iv.size()); |
| 277 EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv)); | 277 EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv)); |
| 278 | 278 |
| 279 std::string ciphertext; | 279 std::string ciphertext; |
| 280 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); | 280 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); |
| 281 EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), | 281 EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), |
| 282 ciphertext.size())); | 282 ciphertext.size())); |
| 283 } | 283 } |
| 284 | |
| 285 TEST(EncryptorTest, EmptyDecrypt) { | |
| 286 std::string key = "128=SixteenBytes"; | |
| 287 std::string iv = "Sweet Sixteen IV"; | |
| 288 | |
| 289 scoped_ptr<crypto::SymmetricKey> sym_key(crypto::SymmetricKey::Import( | |
| 290 crypto::SymmetricKey::AES, key)); | |
| 291 ASSERT_TRUE(NULL != sym_key.get()); | |
| 292 | |
| 293 crypto::Encryptor encryptor; | |
| 294 // The IV must be exactly as long a the cipher block size. | |
| 295 EXPECT_EQ(16U, iv.size()); | |
| 296 EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv)); | |
| 297 | |
| 298 std::string decrypted; | |
| 299 EXPECT_FALSE(encryptor.Decrypt("", &decrypted)); | |
| 300 EXPECT_EQ("", decrypted); | |
| 301 } | |
| OLD | NEW |