1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 17 #ifndef TINK_STREAMING_MAC_H_ 18 #define TINK_STREAMING_MAC_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "absl/strings/string_view.h" 24 #include "tink/output_stream_with_result.h" 25 #include "tink/util/status.h" 26 #include "tink/util/statusor.h" 27 28 namespace crypto { 29 namespace tink { 30 31 /////////////////////////////////////////////////////////////////////////////// 32 // Interface for Streaming MACs (Message Authentication Codes). 33 // This interface should be used for authentication only, and not for other 34 // purposes (e.g., it should not be used to generate pseudorandom bytes). 35 class StreamingMac { 36 public: 37 // Returns an ComputeMacOutputStream, which when closed will return the 38 // message authentication code (MAC) of the data put into the stream. 39 virtual util::StatusOr<std::unique_ptr<OutputStreamWithResult<std::string>>> 40 NewComputeMacOutputStream() const = 0; 41 42 // Returns an VerifyMacOutputStream which verifies if 'mac' is a correct 43 // message authentication code (MAC) for the data written to it. 44 virtual util::StatusOr<std::unique_ptr<OutputStreamWithResult<util::Status>>> 45 NewVerifyMacOutputStream(const std::string& mac_value) const = 0; 46 47 virtual ~StreamingMac() = default; 48 }; 49 50 } // namespace tink 51 } // namespace crypto 52 53 #endif // TINK_STREAMING_MAC_H_ 54