1 // Copyright 2019 Google LLC 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_SUBTLE_STREAMING_MAC_IMPL_H_ 18 #define TINK_SUBTLE_STREAMING_MAC_IMPL_H_ 19 20 #include <memory> 21 #include <string> 22 #include <utility> 23 24 #include "tink/streaming_mac.h" 25 #include "tink/subtle/mac/stateful_mac.h" 26 27 namespace crypto { 28 namespace tink { 29 namespace subtle { 30 31 class StreamingMacImpl : public StreamingMac { 32 public: 33 // Constructor StreamingMacImpl(std::unique_ptr<StatefulMacFactory> mac_factory)34 explicit StreamingMacImpl(std::unique_ptr<StatefulMacFactory> mac_factory) 35 : mac_factory_(std::move(mac_factory)) {} 36 37 // Implement streaming mac class functions 38 // Returns an ComputeMacOutputStream, which when closed will return the 39 // message authentication code (MAC) of the data put into the stream. 40 util::StatusOr<std::unique_ptr<OutputStreamWithResult<std::string>>> 41 NewComputeMacOutputStream() const override; 42 43 // Returns an VerifyMacOutputStream which verifies if 'mac' is a correct 44 // message authentication code (MAC) for the data written to it. 45 util::StatusOr<std::unique_ptr<OutputStreamWithResult<util::Status>>> 46 NewVerifyMacOutputStream(const std::string& mac_value) const override; 47 48 private: 49 std::unique_ptr<StatefulMacFactory> mac_factory_; 50 }; 51 52 } // namespace subtle 53 } // namespace tink 54 } // namespace crypto 55 56 #endif // TINK_SUBTLE_STREAMING_MAC_IMPL_H_ 57