xref: /aosp_15_r20/external/tink/cc/jwt/internal/jwt_ecdsa_verify_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_ECDSA_VERIFY_KEY_MANAGER_H_
17 #define TINK_JWT_INTERNAL_JWT_ECDSA_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_ecdsa_verify_key_manager.h"
27 #include "tink/util/status.h"
28 #include "tink/util/statusor.h"
29 #include "proto/jwt_ecdsa.pb.h"
30 
31 namespace crypto {
32 namespace tink {
33 namespace jwt_internal {
34 
35 class JwtEcdsaVerifyKeyManager
36     : public KeyTypeManager<google::crypto::tink::JwtEcdsaPublicKey, 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::JwtEcdsaPublicKey& jwt_ecdsa_public_key)
43         const override;
44 
45    private:
46     const RawJwtEcdsaVerifyKeyManager raw_key_manager_;
47   };
48 
JwtEcdsaVerifyKeyManager()49   JwtEcdsaVerifyKeyManager()
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::JwtEcdsaPublicKey& key) const override;
61 
62  private:
63   static crypto::tink::util::StatusOr<std::string> AlgorithmName(
64       const google::crypto::tink::JwtEcdsaAlgorithm& algorithm);
65   const RawJwtEcdsaVerifyKeyManager raw_key_manager_;
66   friend class JwtEcdsaSignKeyManager;
67 };
68 
69 }  // namespace jwt_internal
70 }  // namespace tink
71 }  // namespace crypto
72 
73 #endif  // TINK_JWT_INTERNAL_JWT_ECDSA_VERIFY_KEY_MANAGER_H_
74