diff options
Diffstat (limited to 'cc/signature/ed25519_public_key.h')
-rw-r--r-- | cc/signature/ed25519_public_key.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/cc/signature/ed25519_public_key.h b/cc/signature/ed25519_public_key.h new file mode 100644 index 000000000..5deae86a2 --- /dev/null +++ b/cc/signature/ed25519_public_key.h @@ -0,0 +1,81 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef TINK_SIGNATURE_ED25519_PUBLIC_KEY_H_ +#define TINK_SIGNATURE_ED25519_PUBLIC_KEY_H_ + +#include <string> + +#include "absl/types/optional.h" +#include "tink/partial_key_access_token.h" +#include "tink/signature/ed25519_parameters.h" +#include "tink/signature/signature_public_key.h" +#include "tink/util/statusor.h" + +namespace crypto { +namespace tink { + +class Ed25519PublicKey : public SignaturePublicKey { + public: + // Copyable and movable. + Ed25519PublicKey(const Ed25519PublicKey& other) = default; + Ed25519PublicKey& operator=(const Ed25519PublicKey& other) = default; + Ed25519PublicKey(Ed25519PublicKey&& other) = default; + Ed25519PublicKey& operator=(Ed25519PublicKey&& other) = default; + + // Creates a new Ed25519 public key from `public_key_bytes`. If `parameters` + // specify a variant that uses a prefix, then `id_requirement` is used to + // compute this prefix. + static util::StatusOr<Ed25519PublicKey> Create( + const Ed25519Parameters& parameters, absl::string_view public_key_bytes, + absl::optional<int> id_requirement, PartialKeyAccessToken token); + + absl::string_view GetPublicKeyBytes(PartialKeyAccessToken token) const { + return public_key_bytes_; + } + + absl::string_view GetOutputPrefix() const override { return output_prefix_; } + + const Ed25519Parameters& GetParameters() const override { + return parameters_; + } + + absl::optional<int> GetIdRequirement() const override { + return id_requirement_; + } + + bool operator==(const Key& other) const override; + + private: + explicit Ed25519PublicKey(const Ed25519Parameters& parameters, + absl::string_view public_key_bytes, + absl::optional<int> id_requirement, + absl::string_view output_prefix) + : parameters_(parameters), + public_key_bytes_(public_key_bytes), + id_requirement_(id_requirement), + output_prefix_(output_prefix) {} + + Ed25519Parameters parameters_; + std::string public_key_bytes_; + absl::optional<int> id_requirement_; + std::string output_prefix_; +}; + +} // namespace tink +} // namespace crypto + +#endif // TINK_SIGNATURE_ED25519_PUBLIC_KEY_H_ |