xref: /aosp_15_r20/external/tink/cc/signature/public_key_verify_factory.cc (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 #include "tink/signature/public_key_verify_factory.h"
18 
19 #include <memory>
20 
21 #include "tink/key_manager.h"
22 #include "tink/keyset_handle.h"
23 #include "tink/public_key_verify.h"
24 #include "tink/registry.h"
25 #include "tink/signature/public_key_verify_wrapper.h"
26 #include "tink/util/status.h"
27 #include "tink/util/statusor.h"
28 
29 namespace crypto {
30 namespace tink {
31 
32 // static
33 util::StatusOr<std::unique_ptr<PublicKeyVerify>>
GetPrimitive(const KeysetHandle & keyset_handle)34 PublicKeyVerifyFactory::GetPrimitive(const KeysetHandle& keyset_handle) {
35   util::Status status = Registry::RegisterPrimitiveWrapper(
36       absl::make_unique<PublicKeyVerifyWrapper>());
37   if (!status.ok()) {
38     return status;
39   }
40   return keyset_handle.GetPrimitive<PublicKeyVerify>();
41 }
42 
43 // static
44 util::StatusOr<std::unique_ptr<PublicKeyVerify>>
GetPrimitive(const KeysetHandle & keyset_handle,const KeyManager<PublicKeyVerify> * custom_key_manager)45 PublicKeyVerifyFactory::GetPrimitive(
46     const KeysetHandle& keyset_handle,
47     const KeyManager<PublicKeyVerify>* custom_key_manager) {
48   util::Status status = Registry::RegisterPrimitiveWrapper(
49       absl::make_unique<PublicKeyVerifyWrapper>());
50   if (!status.ok()) {
51     return status;
52   }
53   return keyset_handle.GetPrimitive<PublicKeyVerify>(custom_key_manager);
54 }
55 
56 }  // namespace tink
57 }  // namespace crypto
58