| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include <omaha/base/encrypt.h> | |
| 17 #include <cstring> | |
| 18 #include <vector> | |
| 19 #include "omaha/testing/unit_test.h" | |
| 20 | |
| 21 namespace omaha { | |
| 22 | |
| 23 namespace encrypt { | |
| 24 | |
| 25 TEST(EncryptTest, Test) { | |
| 26 const char* plaintext = "the quick brown fox jumps over the lazy dog"; | |
| 27 std::vector<uint8> ciphertext; | |
| 28 EXPECT_HRESULT_SUCCEEDED(EncryptData(NULL, 0, | |
| 29 plaintext, strlen(plaintext), | |
| 30 &ciphertext)); | |
| 31 std::vector<uint8> decrypted_text; | |
| 32 EXPECT_HRESULT_SUCCEEDED(DecryptData(NULL, 0, | |
| 33 &ciphertext.front(), ciphertext.size(), | |
| 34 &decrypted_text)); | |
| 35 EXPECT_EQ(decrypted_text.size(), strlen(plaintext)); | |
| 36 decrypted_text.push_back(0); | |
| 37 EXPECT_STREQ(reinterpret_cast<char*>(&decrypted_text.front()), plaintext); | |
| 38 | |
| 39 | |
| 40 const char* key = "foobar"; | |
| 41 ciphertext.clear(); | |
| 42 EXPECT_HRESULT_SUCCEEDED(EncryptData(key, strlen(key), | |
| 43 plaintext, strlen(plaintext), | |
| 44 &ciphertext)); | |
| 45 decrypted_text.clear(); | |
| 46 EXPECT_HRESULT_SUCCEEDED(DecryptData(key, strlen(key), | |
| 47 &ciphertext.front(), ciphertext.size(), | |
| 48 &decrypted_text)); | |
| 49 EXPECT_EQ(decrypted_text.size(), strlen(plaintext)); | |
| 50 decrypted_text.push_back(0); | |
| 51 EXPECT_STREQ(reinterpret_cast<char*>(&decrypted_text.front()), plaintext); | |
| 52 } | |
| 53 | |
| 54 } // namespace encrypt | |
| 55 | |
| 56 } // namespace omaha | |
| 57 | |
| OLD | NEW |