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

Unified Diff: net/cert/ct_log_verifier_unittest.cc

Issue 2183073002: Improve documentation and readability of CTLogVerifier tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/ct_log_verifier_unittest.cc
diff --git a/net/cert/ct_log_verifier_unittest.cc b/net/cert/ct_log_verifier_unittest.cc
index 754d3e39073c50f89c3c83b1d3d623a7ef782659..ff911d6a14b729f9bd4f0a356fed465b9d86645b 100644
--- a/net/cert/ct_log_verifier_unittest.cc
+++ b/net/cert/ct_log_verifier_unittest.cc
@@ -41,8 +41,8 @@ uint64_t CalculateNearestPowerOfTwo(uint64_t n) {
// A single hash node.
struct TestVector {
- const char* const str;
- size_t length_bytes;
+ const char* const str; // hex string
+ size_t length_bytes; // number of bytes represented by |str|
};
// A single consistency proof. Contains the old and new tree sizes
@@ -61,8 +61,8 @@ struct ProofTestVector {
const TestVector kSHA256EmptyTreeHash = {
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 32};
-// Node hashes for a sample tree of size 8 (each element in this array is
-// a node hash, not leaf data; order represents order of the nodes in the tree).
+// Incremental roots from building the sample tree of size 8 leaf-by-leaf.
+// The first entry is the root at size 0, the last is the root at size 8.
const TestVector kSHA256Roots[8] = {
{"6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d", 32},
{"fac54203e7cc696cf0dfcb42c92a1d9dbaf70ad9e621f4bd8d98662f00e3c125", 32},
@@ -73,8 +73,7 @@ const TestVector kSHA256Roots[8] = {
{"ddb89be403809e325750d3d263cd78929c2942b7942a34b77e122c9594a74c8c", 32},
{"5dc9da79a70659a9ad559cb701ded9a2ab9d823aad2f4960cfe370eff4604328", 32}};
-// A collection of consistency proofs between various sub-trees of the tree
-// defined by |kSHA256Roots|.
+// A collection of consistency proofs between various nodes of the sample tree.
const ProofTestVector kSHA256Proofs[4] = {
// Empty consistency proof between trees of the same size (1).
{1, 1, 0, {{"", 0}, {"", 0}, {"", 0}}},
@@ -115,9 +114,14 @@ std::string HexToBytes(const char* hex_data, size_t hex_data_length) {
return result;
}
+std::string HexToBytes(const TestVector& x) {
+ std::string bytes = HexToBytes(x.str, x.length_bytes * 2);
+ CHECK_EQ(x.length_bytes, bytes.size());
+ return bytes;
+}
+
std::string GetEmptyTreeHash() {
- return HexToBytes(kSHA256EmptyTreeHash.str,
- kSHA256EmptyTreeHash.length_bytes);
Ryan Sleevi 2016/07/26 18:25:14 Wait, so this whole time, the empty tree hash was
Eran Messeri 2016/07/26 18:32:08 Turns out it wasn't, because of a bug in the HexTo
Ryan Sleevi 2016/07/26 18:36:24 So why does this CL leave the bug in place then? (
Rob Percival 2016/08/25 16:23:34 I've broken out a fix for this into https://codere
+ return HexToBytes(kSHA256EmptyTreeHash);
}
// Creates a ct::MerkleConsistencyProof and returns the result of
@@ -379,18 +383,18 @@ TEST_F(CTLogVerifierTest, VerifiesValidConsistencyProofs) {
// Known good proofs.
for (size_t i = 0; i < arraysize(kSHA256Proofs); ++i) {
+ SCOPED_TRACE(i);
proof.clear();
for (size_t j = 0; j < kSHA256Proofs[i].proof_length; ++j) {
const TestVector& v = kSHA256Proofs[i].proof[j];
- proof.push_back(HexToBytes(v.str, v.length_bytes));
+ proof.push_back(HexToBytes(v));
}
const uint64_t snapshot1 = kSHA256Proofs[i].snapshot1;
const uint64_t snapshot2 = kSHA256Proofs[i].snapshot2;
const TestVector& old_root = kSHA256Roots[snapshot1 - 1];
const TestVector& new_root = kSHA256Roots[snapshot2 - 1];
- VerifierConsistencyCheck(
- snapshot1, snapshot2, HexToBytes(old_root.str, old_root.length_bytes),
- HexToBytes(new_root.str, new_root.length_bytes), proof);
+ VerifierConsistencyCheck(snapshot1, snapshot2, HexToBytes(old_root),
+ HexToBytes(new_root), proof);
}
}
@@ -402,10 +406,7 @@ const char kLeafPrefix[] = {'\x00'};
// code.
class TreeHasher {
public:
- static std::string HashEmpty() {
- return HexToBytes(kSHA256EmptyTreeHash.str,
- kSHA256EmptyTreeHash.length_bytes);
- }
+ static std::string HashEmpty() { return HexToBytes(kSHA256EmptyTreeHash); }
static std::string HashLeaf(const std::string& leaf) {
SHA256HashValue sha256;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698