1 // Copyright 2023 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 17 #include "tink/signature/ed25519_parameters.h" 18 19 #include <set> 20 21 #include "tink/util/statusor.h" 22 23 namespace crypto { 24 namespace tink { 25 Create(Variant variant)26util::StatusOr<Ed25519Parameters> Ed25519Parameters::Create(Variant variant) { 27 static const std::set<Variant>* supported_variants = 28 new std::set<Variant>({Variant::kTink, Variant::kCrunchy, 29 Variant::kLegacy, Variant::kNoPrefix}); 30 if (supported_variants->find(variant) == supported_variants->end()) { 31 return util::Status( 32 absl::StatusCode::kInvalidArgument, 33 "Cannot create Ed25519 parameters with unknown variant."); 34 } 35 return Ed25519Parameters(variant); 36 } 37 operator ==(const Parameters & other) const38bool Ed25519Parameters::operator==(const Parameters& other) const { 39 const Ed25519Parameters* that = 40 dynamic_cast<const Ed25519Parameters*>(&other); 41 if (that == nullptr) { 42 return false; 43 } 44 return variant_ == that->variant_; 45 } 46 47 } // namespace tink 48 } // namespace crypto 49