From 7ab44372d81e86df99b3aefa114a5003df98bc61 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Thu, 31 Oct 2019 20:38:27 -0500 Subject: hscript: Implement SigningKey, add tests --- hscript/meta.cc | 21 +++++++++++++++++++++ hscript/meta.hh | 9 ++++++++- hscript/script.cc | 18 +++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) (limited to 'hscript') diff --git a/hscript/meta.cc b/hscript/meta.cc index 5885c1e..640743c 100644 --- a/hscript/meta.cc +++ b/hscript/meta.cc @@ -466,3 +466,24 @@ bool Repository::execute(ScriptOptions opts) const { return false; #endif /* HAS_INSTALL_ENV */ } + + +Key *SigningKey::parseFromData(const std::string &data, int lineno, + int *errors, int *) { + if(data.empty() || (data[0] != '/' && data.compare(0, 8, "https://"))) { + if(errors) *errors += 1; + output_error("installfile:" + std::to_string(lineno), + "signingkey: must be absolute path or HTTPS URL"); + return nullptr; + } + + return new SigningKey(lineno, data); +} + +bool SigningKey::validate(ScriptOptions) const { + return true; +} + +bool SigningKey::execute(ScriptOptions) const { + return false; +} diff --git a/hscript/meta.hh b/hscript/meta.hh index dad4cf3..547349d 100644 --- a/hscript/meta.hh +++ b/hscript/meta.hh @@ -88,7 +88,14 @@ public: bool execute(ScriptOptions) const override; }; -class SigningKey : public Key { +class SigningKey : public StringKey { +private: + SigningKey(int _line, const std::string &_path) : + StringKey(_line, _path) {} +public: + static Key *parseFromData(const std::string &, int, int *, int *); + bool validate(ScriptOptions) const override; + bool execute(ScriptOptions) const override; }; } diff --git a/hscript/script.cc b/hscript/script.cc index 319ba14..ea083a8 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -173,6 +173,10 @@ struct Script::ScriptPrivate { std::unique_ptr repo(dynamic_cast(obj)); this->repos.push_back(std::move(repo)); return true; + } else if(key_name == "signingkey") { + std::unique_ptr key(dynamic_cast(obj)); + this->repo_keys.push_back(std::move(key)); + return true; } else if(key_name == "username") { return store_username(obj, lineno, errors, warnings, opts); } else if(key_name == "useralias") { @@ -808,7 +812,19 @@ bool Script::validate() const { "You may only specify up to 10 repositories."); } - /* signingkey */ + /* REQ: Runner.Validate.signingkey */ + for(auto &key : this->internal->repo_keys) { + if(!key->validate(this->opts)) { + failures++; + } + } + if(this->internal->repo_keys.size() > 10) { + failures++; + output_error("installfile:" + + std::to_string(this->internal->repo_keys[11]->lineno()), + "signingkey: too many keys specified", + "You may only specify up to 10 repository keys."); + } for(auto &acct : this->internal->accounts) { UserDetail *detail = acct.second.get(); -- cgit v1.2.3-60-g2f50