aboutsummaryrefslogtreecommitdiff
path: root/cc/primitive_set.h
diff options
context:
space:
mode:
authorBartosz Przydatek <przydatek@google.com>2017-05-12 14:30:28 +0200
committerThai Duong <thaidn@google.com>2017-05-12 14:34:49 -0700
commit458d2781a5f45201077e46ee97876f80c5d81923 (patch)
tree4f39c0090ce00e206bc975ca9e290d732f319e7d /cc/primitive_set.h
parent0d8cd96e435ddcb6e1481c2f7c900677a8a5677b (diff)
downloadtink-458d2781a5f45201077e46ee97876f80c5d81923.tar.gz
Fixing primitive_set.h
Change-Id: Id7fc33c3827e7820371c3b705e9d3881032d3af5 ORIGINAL_AUTHOR=Bartosz Przydatek <przydatek@google.com> GitOrigin-RevId: c7032365db76585073408c181d18128083ad528b
Diffstat (limited to 'cc/primitive_set.h')
-rw-r--r--cc/primitive_set.h52
1 files changed, 20 insertions, 32 deletions
diff --git a/cc/primitive_set.h b/cc/primitive_set.h
index 7b07adb1f..5adf724ab 100644
--- a/cc/primitive_set.h
+++ b/cc/primitive_set.h
@@ -86,11 +86,29 @@ class PrimitiveSet {
// Adds 'primitive' to this set for the specified 'key'.
util::StatusOr<Entry<P>*> AddPrimitive(
std::unique_ptr<P> primitive,
- google::cloud::crypto::tink::Keyset::Key key);
+ google::cloud::crypto::tink::Keyset::Key key) {
+ auto identifier_result = CryptoFormat::get_output_prefix(key);
+ if (!identifier_result.ok()) return identifier_result.status();
+ std::string identifier = identifier_result.ValueOrDie();
+ std::lock_guard<std::mutex> lock(primitives_mutex_);
+ primitives_[identifier].push_back(
+ Entry<P>(std::move(primitive), identifier, key.status()));
+ return &(primitives_[identifier].back());
+ }
// Returns the entries with primitives identifed by 'identifier'.
util::StatusOr<const Primitives*> get_primitives(
- google::protobuf::StringPiece identifier);
+ google::protobuf::StringPiece identifier) {
+ std::lock_guard<std::mutex> lock(primitives_mutex_);
+ typename CiphertextPrefixToPrimitivesMap::iterator found =
+ primitives_.find(identifier.ToString());
+ if (found == primitives_.end()) {
+ return ToStatusF(util::error::NOT_FOUND,
+ "No primitives found for identifier '%s'.",
+ identifier.ToString().c_str());
+ }
+ return &(found->second);
+ }
// Returns all primitives that use RAW prefix.
util::StatusOr<const Primitives*> get_raw_primitives() {
@@ -115,36 +133,6 @@ class PrimitiveSet {
CiphertextPrefixToPrimitivesMap primitives_; // guarded by primitives_mutex_
};
-///////////////////////////////////////////////////////////////////////////////
-// Implementation details.
-
-template <class P>
-util::StatusOr<PrimitiveSet<P>::Entry<P>*> PrimitiveSet<P>::AddPrimitive(
- std::unique_ptr<P> primitive,
- google::cloud::crypto::tink::Keyset::Key key) {
- auto identifier_result = CryptoFormat::get_output_prefix(key);
- if (!identifier_result.ok()) return identifier_result.status();
- std::string identifier = identifier_result.ValueOrDie();
- std::lock_guard<std::mutex> lock(primitives_mutex_);
- primitives_[identifier].push_back(
- Entry<P>(std::move(primitive), identifier, key.status()));
- return &(primitives_[identifier].back());
-}
-
-template <class P>
-util::StatusOr<const std::vector<PrimitiveSet<P>::Entry<P>>*>
-PrimitiveSet<P>::get_primitives(google::protobuf::StringPiece identifier) {
- std::lock_guard<std::mutex> lock(primitives_mutex_);
- typename CiphertextPrefixToPrimitivesMap::iterator found =
- primitives_.find(identifier.ToString());
- if (found == primitives_.end()) {
- return ToStatusF(util::error::NOT_FOUND,
- "No primitives found for identifier '%s'.",
- identifier.ToString().c_str());
- }
- return &(found->second);
-}
-
} // namespace tink
} // namespace crypto
} // namespace cloud