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_PKCS1_SIGN_KEY_MANAGER_H_ 17 #define TINK_JWT_INTERNAL_JWT_RSA_SSA_PKCS1_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_pkcs1_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_pkcs1.pb.h" 30 31 namespace crypto { 32 namespace tink { 33 namespace jwt_internal { 34 35 class JwtRsaSsaPkcs1SignKeyManager 36 : public PrivateKeyTypeManager< 37 google::crypto::tink::JwtRsaSsaPkcs1PrivateKey, 38 google::crypto::tink::JwtRsaSsaPkcs1KeyFormat, 39 google::crypto::tink::JwtRsaSsaPkcs1PublicKey, 40 List<JwtPublicKeySignInternal>> { 41 public: 42 class PublicKeySignFactory 43 : public PrimitiveFactory<JwtPublicKeySignInternal> { 44 crypto::tink::util::StatusOr<std::unique_ptr<JwtPublicKeySignInternal>> 45 Create(const google::crypto::tink::JwtRsaSsaPkcs1PrivateKey& private_key) 46 const override; 47 48 private: 49 const RawJwtRsaSsaPkcs1SignKeyManager raw_key_manager_; 50 }; 51 JwtRsaSsaPkcs1SignKeyManager()52 JwtRsaSsaPkcs1SignKeyManager() 53 : PrivateKeyTypeManager(absl::make_unique<PublicKeySignFactory>()) {} 54 55 uint32_t get_version() const override; 56 57 google::crypto::tink::KeyData::KeyMaterialType key_material_type() 58 const override; 59 60 const std::string& get_key_type() const override; 61 62 crypto::tink::util::Status ValidateKey( 63 const google::crypto::tink::JwtRsaSsaPkcs1PrivateKey& key) const override; 64 65 crypto::tink::util::Status ValidateKeyFormat( 66 const google::crypto::tink::JwtRsaSsaPkcs1KeyFormat& key_format) 67 const override; 68 69 crypto::tink::util::StatusOr<google::crypto::tink::JwtRsaSsaPkcs1PrivateKey> 70 CreateKey(const google::crypto::tink::JwtRsaSsaPkcs1KeyFormat& key_format) 71 const override; 72 73 crypto::tink::util::StatusOr<google::crypto::tink::JwtRsaSsaPkcs1PublicKey> 74 GetPublicKey(const google::crypto::tink::JwtRsaSsaPkcs1PrivateKey& 75 private_key) const override; 76 77 private: 78 const RawJwtRsaSsaPkcs1SignKeyManager raw_key_manager_; 79 }; 80 81 } // namespace jwt_internal 82 } // namespace tink 83 } // namespace crypto 84 85 #endif // TINK_JWT_INTERNAL_JWT_RSA_SSA_PKCS1_SIGN_KEY_MANAGER_H_ 86