xref: /aosp_15_r20/external/tink/cc/signature/rsa_ssa_pkcs1_verify_key_manager.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_SIGNATURE_RSA_SSA_PKCS1_VERIFY_KEY_MANAGER_H_
18 #define TINK_SIGNATURE_RSA_SSA_PKCS1_VERIFY_KEY_MANAGER_H_
19 
20 #include <algorithm>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "absl/memory/memory.h"
26 #include "absl/strings/str_cat.h"
27 #include "tink/core/key_type_manager.h"
28 #include "tink/public_key_verify.h"
29 #include "tink/util/constants.h"
30 #include "tink/util/errors.h"
31 #include "tink/util/protobuf_helper.h"
32 #include "tink/util/status.h"
33 #include "tink/util/statusor.h"
34 #include "proto/rsa_ssa_pkcs1.pb.h"
35 
36 namespace crypto {
37 namespace tink {
38 
39 class RsaSsaPkcs1VerifyKeyManager
40     : public KeyTypeManager<google::crypto::tink::RsaSsaPkcs1PublicKey, void,
41                             List<PublicKeyVerify>> {
42  public:
43   class PublicKeyVerifyFactory : public PrimitiveFactory<PublicKeyVerify> {
44     crypto::tink::util::StatusOr<std::unique_ptr<PublicKeyVerify>> Create(
45         const google::crypto::tink::RsaSsaPkcs1PublicKey&
46             rsa_ssa_pkcs1_public_key) const override;
47   };
48 
RsaSsaPkcs1VerifyKeyManager()49   RsaSsaPkcs1VerifyKeyManager()
50       : KeyTypeManager(absl::make_unique<PublicKeyVerifyFactory>()) {}
51 
get_version()52   uint32_t get_version() const override { return 0; }
53 
key_material_type()54   google::crypto::tink::KeyData::KeyMaterialType key_material_type()
55       const override {
56     return google::crypto::tink::KeyData::ASYMMETRIC_PUBLIC;
57   }
58 
get_key_type()59   const std::string& get_key_type() const override { return key_type_; }
60 
61   crypto::tink::util::Status ValidateKey(
62       const google::crypto::tink::RsaSsaPkcs1PublicKey& key) const override;
63 
64   crypto::tink::util::Status ValidateParams(
65       const google::crypto::tink::RsaSsaPkcs1Params& params) const;
66 
FipsStatus()67   internal::FipsCompatibility FipsStatus() const override {
68     return internal::FipsCompatibility::kRequiresBoringCrypto;
69   }
70 
71  private:
72   const std::string key_type_ =
73       absl::StrCat(kTypeGoogleapisCom,
74                    google::crypto::tink::RsaSsaPkcs1PublicKey().GetTypeName());
75 };
76 
77 }  // namespace tink
78 }  // namespace crypto
79 
80 #endif  // TINK_SIGNATURE_RSA_SSA_PKCS1_VERIFY_KEY_MANAGER_H_
81