Skip to content
Merged
16 changes: 10 additions & 6 deletions src/Keystore/ScryptParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ static const auto r = "r";
ScryptParameters::ScryptParameters(const nlohmann::json& json) {
salt = parse_hex(json[CodingKeys::SP::salt].get<std::string>());
desiredKeyLength = json[CodingKeys::SP::desiredKeyLength];
if (json.count(CodingKeys::SP::n) != 0)
n = json[CodingKeys::SP::n];
if (json.count(CodingKeys::SP::n) != 0)
p = json[CodingKeys::SP::p];
if (json.count(CodingKeys::SP::n) != 0)
r = json[CodingKeys::SP::r];
if (json.count(CodingKeys::SP::n) == 0
|| json.count(CodingKeys::SP::p) == 0
|| json.count(CodingKeys::SP::r) == 0) {
throw std::invalid_argument("Missing required scrypt parameters n, p, or r");
}
if (const auto error = validate()) {
std::stringstream ss;
ss << "Invalid scrypt parameters: " << static_cast<int>(*error);
throw std::invalid_argument(ss.str());
}
}

/// Saves `this` as a JSON object.
Expand Down
Loading