xref: /aosp_15_r20/external/tink/cc/aead/aead_factory.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
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_AEAD_AEAD_FACTORY_H_
18 #define TINK_AEAD_AEAD_FACTORY_H_
19 
20 #include <memory>
21 
22 #include "absl/base/attributes.h"
23 #include "tink/aead.h"
24 #include "tink/key_manager.h"
25 #include "tink/keyset_handle.h"
26 #include "tink/util/statusor.h"
27 
28 namespace crypto {
29 namespace tink {
30 
31 ///////////////////////////////////////////////////////////////////////////////
32 // This class is deprecated. Call keyset_handle->GetPrimitive<Aead>() instead.
33 //
34 // Note that in order to for this change to be safe, the AeadSetWrapper has to
35 // be registered in your binary before this call. This happens automatically if
36 // you call one of
37 // * AeadConfig::Register()
38 // * HybridConfig::Register()
39 // * TinkConfig::Register()
40 class ABSL_DEPRECATED(
41     "Call GetPrimitive<Aead>() on the keyset_handle after registering the "
42     "AeadWrapper instead.") AeadFactory {
43  public:
44   // Returns an Aead-primitive that uses key material from the keyset
45   // specified via 'keyset_handle'.
46   static crypto::tink::util::StatusOr<std::unique_ptr<Aead>> GetPrimitive(
47       const KeysetHandle& keyset_handle);
48 
49   // Returns an Aead-primitive that uses key material from the keyset
50   // specified via 'keyset_handle' and is instantiated by the given
51   // 'custom_key_manager' (instead of the key manager from the Registry).
52   static crypto::tink::util::StatusOr<std::unique_ptr<Aead>> GetPrimitive(
53       const KeysetHandle& keyset_handle,
54       const KeyManager<Aead>* custom_key_manager);
55 
56  private:
AeadFactory()57   AeadFactory() {}
58 };
59 
60 }  // namespace tink
61 }  // namespace crypto
62 
63 #endif  // TINK_AEAD_AEAD_FACTORY_H_
64