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_VERIFY_KEY_MANAGER_H_ 17 #define TINK_JWT_INTERNAL_JWT_RSA_SSA_PKCS1_VERIFY_KEY_MANAGER_H_ 18 19 #include <memory> 20 #include <string> 21 22 #include "absl/memory/memory.h" 23 #include "tink/core/key_type_manager.h" 24 #include "tink/jwt/internal/jwt_public_key_verify_impl.h" 25 #include "tink/jwt/internal/jwt_public_key_verify_internal.h" 26 #include "tink/jwt/internal/raw_jwt_rsa_ssa_pkcs1_verify_key_manager.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 JwtRsaSsaPkcs1VerifyKeyManager 36 : public KeyTypeManager<google::crypto::tink::JwtRsaSsaPkcs1PublicKey, void, 37 List<JwtPublicKeyVerifyInternal>> { 38 public: 39 class PublicKeyVerifyFactory 40 : public PrimitiveFactory<JwtPublicKeyVerifyInternal> { 41 crypto::tink::util::StatusOr<std::unique_ptr<JwtPublicKeyVerifyInternal>> 42 Create(const google::crypto::tink::JwtRsaSsaPkcs1PublicKey& 43 jwt_rsa_ssa_pkcs1_public_key) const override; 44 45 private: 46 const RawJwtRsaSsaPkcs1VerifyKeyManager raw_key_manager_; 47 }; 48 JwtRsaSsaPkcs1VerifyKeyManager()49 JwtRsaSsaPkcs1VerifyKeyManager() 50 : KeyTypeManager(absl::make_unique<PublicKeyVerifyFactory>()) {} 51 52 uint32_t get_version() const override; 53 54 google::crypto::tink::KeyData::KeyMaterialType key_material_type() 55 const override; 56 57 const std::string& get_key_type() const override; 58 59 crypto::tink::util::Status ValidateKey( 60 const google::crypto::tink::JwtRsaSsaPkcs1PublicKey& key) const override; 61 62 private: 63 static crypto::tink::util::StatusOr<std::string> AlgorithmName( 64 const google::crypto::tink::JwtRsaSsaPkcs1Algorithm& algorithm); 65 const RawJwtRsaSsaPkcs1VerifyKeyManager raw_key_manager_; 66 friend class JwtRsaSsaPkcs1SignKeyManager; 67 }; 68 69 } // namespace jwt_internal 70 } // namespace tink 71 } // namespace crypto 72 73 #endif // TINK_JWT_INTERNAL_JWT_RSA_SSA_PKCS1_VERIFY_KEY_MANAGER_H_ 74