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

Unified Diff: crypto/symmetric_key_unittest.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: c Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: crypto/symmetric_key_unittest.cc
diff --git a/crypto/symmetric_key_unittest.cc b/crypto/symmetric_key_unittest.cc
index a07194ec0bb8d42c6202d3377e4bb15168320eef..77474c5ff1868ac10e24717eb6b94a575030c699 100644
--- a/crypto/symmetric_key_unittest.cc
+++ b/crypto/symmetric_key_unittest.cc
@@ -4,6 +4,7 @@
#include "crypto/symmetric_key.h"
+#include <algorithm>
#include <string>
#include "base/memory/scoped_ptr.h"
@@ -30,6 +31,16 @@ TEST(SymmetricKeyTest, GenerateRandomKey) {
EXPECT_NE(raw_key, raw_key2);
}
+TEST(SymmetricKeyTest, GenerateRandomBytes) {
+ std::vector<uint8> bytes(50);
+ ASSERT_TRUE(crypto::SymmetricKey::GenerateRandomBytes(
+ bytes.size(), &bytes[0]));
+ // Probability of occurrence of less than 25 unique bytes in 50 random bytes
+ // is below 10^-25.
+ std::sort(bytes.begin(), bytes.end());
+ ASSERT_GT(std::unique(bytes.begin(), bytes.end()) - bytes.begin(), 25);
+}
+
TEST(SymmetricKeyTest, ImportGeneratedKey) {
scoped_ptr<crypto::SymmetricKey> key1(
crypto::SymmetricKey::GenerateRandomKey(crypto::SymmetricKey::AES, 256));

Powered by Google App Engine
This is Rietveld 408576698