Asylo
named_identity_expectation_matcher.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 Asylo authors
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef ASYLO_IDENTITY_NAMED_IDENTITY_EXPECTATION_MATCHER_H_
20 #define ASYLO_IDENTITY_NAMED_IDENTITY_EXPECTATION_MATCHER_H_
21 
22 #include <string>
23 
24 #include "asylo/identity/identity.pb.h"
25 #include "asylo/identity/identity_expectation_matcher.h"
26 #include "asylo/platform/common/static_map.h"
27 #include "asylo/util/statusor.h"
28 
29 namespace asylo {
30 
31 /// A `NamedIdentityExpectationMatcher` is capable of matching an identity to an
32 /// expectation if the identity and the expectation's reference identity have
33 /// the same identity descriptions, and they match the identity description
34 /// returned by the `Description()` method of the matcher. A
35 /// `NamedIdentityExpectationMatcher` is assigned a name based on the identity
36 /// description it handles. All subclasses of this class must be marked `final`.
38  public:
40 
41  // Mark the named identity expectation matcher as non-copyable and
42  // non-movable.
44  const NamedIdentityExpectationMatcher &other) = delete;
46  delete;
48  const NamedIdentityExpectationMatcher &other) = delete;
50  NamedIdentityExpectationMatcher &&other) = delete;
51 
52  /// Returns the description of the enclave identities/enclave identity
53  /// expectations this matcher is able to match. If the `MatchAndExplain()`
54  /// method of this matcher is invoked with an identity or expectation with a
55  /// different description, the matcher returns a non-OK status.
56  ///
57  /// \return A description of the enclave identities/enclave identity
58  /// expectations this matcher is able to match.
59  virtual EnclaveIdentityDescription Description() const = 0;
60 
61  /// Converts `description` to a name that can be used as a unique identifier
62  /// for a `NamedIdentityExpectationMatcher` that handles
63  /// identities/expectations of this description.
64  ///
65  /// \param description The description to get a name for.
66  /// \return A unique identifying string for `description`.
69 };
70 
71 template <>
72 struct Namer<NamedIdentityExpectationMatcher> {
73  std::string operator()(const NamedIdentityExpectationMatcher &matcher) {
74  return NamedIdentityExpectationMatcher::GetMatcherName(
75  matcher.Description())
76  .value();
77  }
78 };
79 
82 
83 } // namespace asylo
84 
85 #endif // ASYLO_IDENTITY_NAMED_IDENTITY_EXPECTATION_MATCHER_H_
DEFINE_STATIC_MAP_OF_BASE_TYPE(IdentityExpectationMatcherMap, NamedIdentityExpectationMatcher)
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
A NamedIdentityExpectationMatcher is capable of matching an identity to an expectation if the identit...
Definition: named_identity_expectation_matcher.h:37
static StatusOr< std::string > GetMatcherName(const EnclaveIdentityDescription &description)
Converts description to a name that can be used as a unique identifier for a NamedIdentityExpectation...
std::string operator()(const NamedIdentityExpectationMatcher &matcher)
Definition: named_identity_expectation_matcher.h:73
NamedIdentityExpectationMatcher & operator=(const NamedIdentityExpectationMatcher &other)=delete
NamedIdentityExpectationMatcher(const NamedIdentityExpectationMatcher &other)=delete
virtual EnclaveIdentityDescription Description() const =0
Returns the description of the enclave identities/enclave identity expectations this matcher is able ...
NamedIdentityExpectationMatcher(NamedIdentityExpectationMatcher &&other)=delete
NamedIdentityExpectationMatcher & operator=(NamedIdentityExpectationMatcher &&other)=delete