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

Side by Side Diff: crypto/aead_openssl_unittest.cc

Issue 1083493003: Encrypt certificate reports before uploading to HTTP URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make nonce/key length static functions on Aead Created 5 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "crypto/aead_openssl.h"
6
7 #include <string>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace {
12
13 #if defined(USE_OPENSSL)
14
15 TEST(AeadTest, SealOpen) {
16 std::string key(crypto::Aead::KeyLength(), 0);
17 crypto::Aead aead(&key);
18 std::string nonce(crypto::Aead::NonceLength(), 0);
19 std::string plaintext("this is the plaintext");
20 std::string ciphertext;
21 EXPECT_TRUE(aead.Seal(plaintext, nonce, &ciphertext));
22 EXPECT_LT(0U, ciphertext.size());
23
24 std::string decrypted;
25 EXPECT_TRUE(aead.Open(ciphertext, nonce, &decrypted));
26
27 EXPECT_EQ(plaintext, decrypted);
28 }
29
30 TEST(AeadTest, SealOpenWrongKey) {
31 std::string key(crypto::Aead::KeyLength(), 0);
32 std::string wrong_key(crypto::Aead::KeyLength(), 1);
33 crypto::Aead aead(&key);
34 crypto::Aead aead_wrong_key(&wrong_key);
35
36 std::string nonce(crypto::Aead::NonceLength(), 0);
37 std::string plaintext("this is the plaintext");
38 std::string ciphertext;
39 EXPECT_TRUE(aead.Seal(plaintext, nonce, &ciphertext));
40 EXPECT_LT(0U, ciphertext.size());
41
42 std::string decrypted;
43 EXPECT_FALSE(aead_wrong_key.Open(ciphertext, nonce, &decrypted));
44 EXPECT_EQ(0U, decrypted.size());
45 }
46
47 #endif
48
49 } // namespace
OLDNEW
« crypto/aead_openssl.h ('K') | « crypto/aead_openssl.cc ('k') | crypto/crypto.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698