Skip to content

Commit

Permalink
perf: some boring things
Browse files Browse the repository at this point in the history
  • Loading branch information
ruitard committed Oct 1, 2022
1 parent 7a6ad6b commit 9df6559
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cli/json_sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ static keycore::buffer json_content_join(const nlohmann::ordered_json &json_root
}

static void sign_json_file() {
fs::path prikey{prikey_file};
const fs::path prikey{prikey_file};
require(fs::is_regular_file(prikey), "the key file not exist");

parse_json_file(json_file);
require(!root.contains(json_signature_name), "the json file already has a signature");

keycore::buffer content = json_content_join(root);
const keycore::buffer content = json_content_join(root);

keycore::buffer signature = keycore::base64::encode(keycore::pk::sign(content, prikey));
root[json_signature_name] = std::string(reinterpret_cast<char *>(signature.data()), signature.size());
const keycore::buffer signature = keycore::base64::encode(keycore::pk::sign(content, prikey));
root[json_signature_name] = std::string_view(reinterpret_cast<const char *>(signature.data()), signature.size());
const auto result = root.dump(4);
if (signed_json_file.empty()) {
std::cout << result << std::endl;
Expand All @@ -73,14 +73,14 @@ static void sign_json_file() {
}

static bool verify_json_file() {
fs::path pubkey{pubkey_file};
const fs::path pubkey{pubkey_file};
require(fs::is_regular_file(pubkey), "the key file not exist");

parse_json_file(signed_json_file);
require(root.contains(json_signature_name), "the json file doesn't have a signature");
std::string signature = root[json_signature_name];
const std::string signature = root[json_signature_name];
root.erase(json_signature_name);
keycore::buffer content = json_content_join(root);
const keycore::buffer content = json_content_join(root);

return keycore::pk::verify(content, keycore::base64::decode(keycore::buffer(signature.begin(), signature.end())),
pubkey);
Expand Down

0 comments on commit 9df6559

Please sign in to comment.