xref: /aosp_15_r20/external/tink/cc/primitive_wrapper.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2018 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_PRIMITIVE_WRAPPER_H_
18 #define TINK_PRIMITIVE_WRAPPER_H_
19 
20 #include <memory>
21 
22 #include "tink/primitive_set.h"
23 #include "tink/util/statusor.h"
24 
25 namespace crypto {
26 namespace tink {
27 
28 // A PrimitiveWrapper knows how to wrap multiple instances of a primitive to
29 // a single instance, enabling key-rotation. It requires a
30 // PrimitiveSet<Primitive> and wraps it into a single primitive.
31 //
32 // PrimitiveWrappers need to be written for every new primitive. They can be
33 // registered in the registry to be fully integrated in Tink.
34 template <typename InputPrimitiveParam, typename PrimitiveParam>
35 class PrimitiveWrapper {
36  public:
37   virtual ~PrimitiveWrapper() = default;
38 
39   // Useful when writing templated code.
40   using InputPrimitive = InputPrimitiveParam;
41   using Primitive = PrimitiveParam;
42 
43   virtual crypto::tink::util::StatusOr<std::unique_ptr<Primitive>> Wrap(
44       std::unique_ptr<PrimitiveSet<InputPrimitive>> primitive_set) const = 0;
45 };
46 
47 }  // namespace tink
48 }  // namespace crypto
49 
50 #endif  // TINK_PRIMITIVE_WRAPPER_H_
51