xref: /aosp_15_r20/external/tink/cc/jwt/internal/jwt_rsa_ssa_pss_sign_key_manager.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2021 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 #ifndef TINK_JWT_INTERNAL_JWT_RSA_SSA_PSS_SIGN_KEY_MANAGER_H_
17 #define TINK_JWT_INTERNAL_JWT_RSA_SSA_PSS_SIGN_KEY_MANAGER_H_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "absl/memory/memory.h"
23 #include "tink/core/private_key_type_manager.h"
24 #include "tink/jwt/internal/jwt_public_key_sign_internal.h"
25 #include "tink/jwt/internal/raw_jwt_rsa_ssa_pss_sign_key_manager.h"
26 #include "tink/jwt/jwt_public_key_sign.h"
27 #include "tink/util/status.h"
28 #include "tink/util/statusor.h"
29 #include "proto/jwt_rsa_ssa_pss.pb.h"
30 
31 namespace crypto {
32 namespace tink {
33 namespace jwt_internal {
34 
35 class JwtRsaSsaPssSignKeyManager
36     : public PrivateKeyTypeManager<google::crypto::tink::JwtRsaSsaPssPrivateKey,
37                                    google::crypto::tink::JwtRsaSsaPssKeyFormat,
38                                    google::crypto::tink::JwtRsaSsaPssPublicKey,
39                                    List<JwtPublicKeySignInternal>> {
40  public:
41   class PublicKeySignFactory
42       : public PrimitiveFactory<JwtPublicKeySignInternal> {
43     crypto::tink::util::StatusOr<std::unique_ptr<JwtPublicKeySignInternal>>
44     Create(const google::crypto::tink::JwtRsaSsaPssPrivateKey& private_key)
45         const override;
46 
47    private:
48     const RawJwtRsaSsaPssSignKeyManager raw_key_manager_;
49   };
50 
JwtRsaSsaPssSignKeyManager()51   JwtRsaSsaPssSignKeyManager()
52       : PrivateKeyTypeManager(absl::make_unique<PublicKeySignFactory>()) {}
53 
54   uint32_t get_version() const override;
55 
56   google::crypto::tink::KeyData::KeyMaterialType key_material_type()
57       const override;
58 
59   const std::string& get_key_type() const override;
60 
61   crypto::tink::util::Status ValidateKey(
62       const google::crypto::tink::JwtRsaSsaPssPrivateKey& key) const override;
63 
64   crypto::tink::util::Status ValidateKeyFormat(
65       const google::crypto::tink::JwtRsaSsaPssKeyFormat& key_format)
66       const override;
67 
68   crypto::tink::util::StatusOr<google::crypto::tink::JwtRsaSsaPssPrivateKey>
69   CreateKey(const google::crypto::tink::JwtRsaSsaPssKeyFormat& key_format)
70       const override;
71 
72   crypto::tink::util::StatusOr<google::crypto::tink::JwtRsaSsaPssPublicKey>
73   GetPublicKey(const google::crypto::tink::JwtRsaSsaPssPrivateKey& private_key)
74       const override;
75 
76  private:
77   const RawJwtRsaSsaPssSignKeyManager raw_key_manager_;
78 };
79 
80 }  // namespace jwt_internal
81 }  // namespace tink
82 }  // namespace crypto
83 
84 #endif  // TINK_JWT_INTERNAL_JWT_RSA_SSA_PSS_SIGN_KEY_MANAGER_H_
85