OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 318 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
319 unsigned char buf[16]; | 319 unsigned char buf[16]; |
320 | 320 |
321 // Increment 10 times. | 321 // Increment 10 times. |
322 crypto::Encryptor::Counter counter1( | 322 crypto::Encryptor::Counter counter1( |
323 std::string(reinterpret_cast<const char*>(kTest1), kCounterSize)); | 323 std::string(reinterpret_cast<const char*>(kTest1), kCounterSize)); |
324 for (int i = 0; i < 10; ++i) | 324 for (int i = 0; i < 10; ++i) |
325 counter1.Increment(); | 325 counter1.Increment(); |
326 counter1.Write(buf); | 326 counter1.Write(buf); |
327 EXPECT_EQ(0, memcmp(buf, kTest1, 15)); | 327 EXPECT_EQ(0, memcmp(buf, kTest1, 15)); |
328 EXPECT_TRUE(buf[15] == 10); | 328 EXPECT_EQ(10, buf[15]); |
329 | 329 |
330 // Check corner cases. | 330 // Check corner cases. |
331 const unsigned char kTest2[] = { | 331 const unsigned char kTest2[] = { |
332 0, 0, 0, 0, 0, 0, 0, 0, | 332 0, 0, 0, 0, 0, 0, 0, 0, |
333 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | 333 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
334 }; | 334 }; |
335 const unsigned char kExpect2[] = | 335 const unsigned char kExpect2[] = |
336 {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}; | 336 {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}; |
337 crypto::Encryptor::Counter counter2( | 337 crypto::Encryptor::Counter counter2( |
338 std::string(reinterpret_cast<const char*>(kTest2), kCounterSize)); | 338 std::string(reinterpret_cast<const char*>(kTest2), kCounterSize)); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 // | 523 // |
524 // Otherwise when using std::string as the other tests do, accesses several | 524 // Otherwise when using std::string as the other tests do, accesses several |
525 // bytes off the end of the buffer may fall inside the reservation of | 525 // bytes off the end of the buffer may fall inside the reservation of |
526 // the string and not be detected. | 526 // the string and not be detected. |
527 std::unique_ptr<char[]> ciphertext(new char[1]); | 527 std::unique_ptr<char[]> ciphertext(new char[1]); |
528 | 528 |
529 std::string plaintext; | 529 std::string plaintext; |
530 EXPECT_FALSE( | 530 EXPECT_FALSE( |
531 encryptor.Decrypt(base::StringPiece(ciphertext.get(), 1), &plaintext)); | 531 encryptor.Decrypt(base::StringPiece(ciphertext.get(), 1), &plaintext)); |
532 } | 532 } |
OLD | NEW |