xref: /aosp_15_r20/external/tink/cc/signature/ed25519_verify_key_manager.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2019 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 #ifndef TINK_SIGNATURE_ED25519_VERIFY_KEY_MANAGER_H_
17 #define TINK_SIGNATURE_ED25519_VERIFY_KEY_MANAGER_H_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "absl/memory/memory.h"
23 #include "absl/strings/str_cat.h"
24 #include "tink/core/key_type_manager.h"
25 #include "tink/public_key_verify.h"
26 #include "tink/util/constants.h"
27 #include "tink/util/errors.h"
28 #include "tink/util/protobuf_helper.h"
29 #include "tink/util/status.h"
30 #include "tink/util/statusor.h"
31 #include "proto/ed25519.pb.h"
32 
33 namespace crypto {
34 namespace tink {
35 
36 class Ed25519VerifyKeyManager
37     : public KeyTypeManager<google::crypto::tink::Ed25519PublicKey, void,
38                             List<PublicKeyVerify>> {
39  public:
40   class PublicKeyVerifyFactory : public PrimitiveFactory<PublicKeyVerify> {
41     crypto::tink::util::StatusOr<std::unique_ptr<PublicKeyVerify>> Create(
42         const google::crypto::tink::Ed25519PublicKey& ecdsa_public_key)
43         const override;
44   };
45 
Ed25519VerifyKeyManager()46   Ed25519VerifyKeyManager()
47       : KeyTypeManager(absl::make_unique<PublicKeyVerifyFactory>()) {}
48 
get_version()49   uint32_t get_version() const override { return 0; }
50 
key_material_type()51   google::crypto::tink::KeyData::KeyMaterialType key_material_type()
52       const override {
53     return google::crypto::tink::KeyData::ASYMMETRIC_PUBLIC;
54   }
55 
get_key_type()56   const std::string& get_key_type() const override { return key_type_; }
57 
58   crypto::tink::util::Status ValidateKey(
59       const google::crypto::tink::Ed25519PublicKey& key) const override;
60 
61  private:
62   const std::string key_type_ =
63       absl::StrCat(kTypeGoogleapisCom,
64                    google::crypto::tink::Ed25519PublicKey().GetTypeName());
65 };
66 
67 }  // namespace tink
68 }  // namespace crypto
69 
70 #endif  // TINK_SIGNATURE_ED25519_VERIFY_KEY_MANAGER_H_
71