File: verifiable_map.cc

package info (click to toggle)
golang-github-google-certificate-transparency 0.0~git20160709.0.0f6e3d1~ds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 5,676 kB
  • sloc: cpp: 35,278; python: 11,838; java: 1,911; sh: 1,885; makefile: 950; xml: 520; ansic: 225
file content (50 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <array>
#include <string>

#include "merkletree/verifiable_map.h"


using std::string;
using std::unique_ptr;
using std::vector;
using util::Status;
using util::StatusOr;


namespace cert_trans {


VerifiableMap::VerifiableMap(SerialHasher* hasher)
    : hasher_model_(CHECK_NOTNULL(hasher)->Create()), merkle_tree_(hasher) {
}


void VerifiableMap::Set(const string& key, const string& value) {
  const SparseMerkleTree::Path path(PathFromKey(key));
  merkle_tree_.SetLeaf(path, value);
  values_[path] = value;
}


StatusOr<string> VerifiableMap::Get(const string& key) const {
  const SparseMerkleTree::Path path(PathFromKey(key));
  const auto it(values_.find(path));
  if (it == values_.end()) {
    return Status(util::error::NOT_FOUND, "No such entry.");
  }
  return it->second;
}


vector<string> VerifiableMap::InclusionProof(const string& key) {
  return merkle_tree_.InclusionProof(PathFromKey(key));
}


SparseMerkleTree::Path VerifiableMap::PathFromKey(const string& key) const {
  unique_ptr<SerialHasher> h(hasher_model_->Create());
  h->Update(key);
  return PathFromBytes(h->Final());
}

}  // namespace cert_trans