Asylo
identity_expectation_matcher.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 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_IDENTITY_EXPECTATION_MATCHER_H_
20 #define ASYLO_IDENTITY_IDENTITY_EXPECTATION_MATCHER_H_
21 
22 #include <string>
23 
24 #include "absl/base/macros.h"
25 #include "asylo/identity/identity.pb.h"
26 #include "asylo/util/statusor.h"
27 
28 namespace asylo {
29 
30 /// Defines an abstract interface that describes how to match an
31 /// `EnclaveIdentity` against an `EnclaveIdentityExpectation`.
32 ///
33 /// All implementations of this interface are expected to be thread-safe.
35  public:
36  IdentityExpectationMatcher() = default;
37  virtual ~IdentityExpectationMatcher() = default;
38 
39  /// Evaluates whether `identity` matches `expectation`.
40  ///
41  /// Evaluating `identity` against `expectation` produces a boolean result
42  /// indicating whether `identity` matches `expectation`, but only if the
43  /// inputs are valid for this matcher. Otherwise, if `matcher` does not
44  /// understand either `identity` or `expectation`, this method returns a
45  /// non-OK Status. This can happen if any of the following is true:
46  ///
47  /// * `identity.description()` is unrecognized by the matcher
48  /// * `expectation.reference_identity().description()` is unrecognized by the
49  /// matcher
50  /// * `identity` and/or `expectation` is malformed
51  ///
52  /// An IdentityExpectationMatcher's MatchAndExplain() implementation is not
53  /// obliged to handle all possible `EnclaveIdentity` and
54  /// `EnclaveIdentityExpectation` protos. Rather, each implementation of
55  /// IdentityExpectationMatcher is free to refine expectations on what kinds of
56  /// `EnclaveIdentity` and `EnclaveIdentityExpectation` arguments it can
57  /// handle. It is up to the caller of this method to provide inputs that fit
58  /// the expectations of the underlying matcher implementation.
59  ///
60  /// The `explanation` parameter, is populated with an explanation of why the
61  /// match failed in the case that this method returns false. `explanation` can
62  /// be nullptr, in which case it is ignored.
63  ///
64  /// \param identity An identity to match.
65  /// \param expectation The identity expectation to match against.
66  /// \param[out] explanation An explanation of why the match failed, if the
67  /// return value was false.
68  /// \return A bool indicating whether the match succeeded, or a non-OK Status
69  /// in the case of invalid arguments.
70  virtual StatusOr<bool> MatchAndExplain(
73  std::string *explanation) const = 0;
74 
75  /// Shim for `MatchAndExplain` that does not support an explanation output
76  /// string.
77  /// \deprecated Use MatchAndExplain instead
78  ABSL_DEPRECATED("Use MatchAndExplain instead")
79  virtual StatusOr<bool> Match(
82  return MatchAndExplain(identity, expectation, /*explanation=*/nullptr);
83  }
84 };
85 
86 } // namespace asylo
87 
88 #endif // ASYLO_IDENTITY_IDENTITY_EXPECTATION_MATCHER_H_
virtual StatusOr< bool > Match(const EnclaveIdentity &identity, const EnclaveIdentityExpectation &expectation) const
Shim for MatchAndExplain that does not support an explanation output string.
Definition: identity_expectation_matcher.h:79
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
virtual StatusOr< bool > MatchAndExplain(const EnclaveIdentity &identity, const EnclaveIdentityExpectation &expectation, std::string *explanation) const =0
Evaluates whether identity matches expectation.
virtual ~IdentityExpectationMatcher()=default