aboutsummaryrefslogtreecommitdiff
path: root/cc/mac/failing_mac.h
diff options
context:
space:
mode:
authorkste <kste@google.com>2022-06-15 08:54:15 -0700
committerCopybara-Service <copybara-worker@google.com>2022-06-15 08:55:19 -0700
commitdcf495fd7d5cecfda42298feca128f25f687bc07 (patch)
tree4e2b23e2e63ac1eb77e70824f88d450dd5419a52 /cc/mac/failing_mac.h
parentfce15973f9fc3a8d504ce9e9ffcf8f9aafe241b7 (diff)
downloadtink-dcf495fd7d5cecfda42298feca128f25f687bc07.tar.gz
Add a method to create an always failing Mac.
This allows to create Mac objects which will return an error on any API call, which can for instance be used for testing correct failure behavior. PiperOrigin-RevId: 455141793
Diffstat (limited to 'cc/mac/failing_mac.h')
-rw-r--r--cc/mac/failing_mac.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/cc/mac/failing_mac.h b/cc/mac/failing_mac.h
new file mode 100644
index 000000000..4eed37dea
--- /dev/null
+++ b/cc/mac/failing_mac.h
@@ -0,0 +1,34 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+///////////////////////////////////////////////////////////////////////////////
+#ifndef TINK_MAC_FAILING_MAC_H_
+#define TINK_MAC_FAILING_MAC_H_
+
+#include <string>
+
+#include "absl/strings/string_view.h"
+#include "tink/mac.h"
+
+namespace crypto {
+namespace tink {
+
+// Returns a MAC that always returns an error when calling ComputeMac or
+// VerifyMac. The error message will contain `message`.
+std::unique_ptr<Mac> CreateAlwaysFailingMac(std::string message = "");
+
+} // namespace tink
+} // namespace crypto
+
+#endif // TINK_MAC_FAILING_MAC_H_