codex32: provide user-readable error types

Github-Pull: #27351
Rebased-From: 1fa04b11b2452a2f15906d97cf1370d43f0dc23e
This commit is contained in:
Andrew Poelstra 2023-03-27 21:47:52 +00:00 committed by Luke Dashjr
parent 3110257f5a
commit c85de09d88
2 changed files with 22 additions and 0 deletions

View File

@ -220,6 +220,26 @@ uint8_t lagrange_coefficient(std::vector<uint8_t>& indices, uint8_t idx, uint8_t
} // namespace
std::string ErrorString(Error e) {
switch (e) {
case OK: return "ok";
case BAD_CHECKSUM: return "bad checksum";
case BECH32_DECODE: return "bech32 decode failure (invalid character, no HRP, or inconsistent case)";
case INVALID_HRP: return "hrp differed from 'ms'";
case INVALID_ID_LEN: return "seed ID was not 4 characters";
case INVALID_ID_CHAR: return "seed ID used a non-bech32 character";
case INVALID_LENGTH: return "invalid length";
case INVALID_K: return "invalid threshold (k) value";
case INVALID_SHARE_IDX: return "invalid share index";
case TOO_FEW_SHARES: return "tried to derive a share but did not have enough input shares";
case DUPLICATE_SHARE: return "tried to derive a share but two input shares had the same index";
case MISMATCH_K: return "tried to derive a share but input shares had inconsistent threshold (k) values";
case MISMATCH_ID: return "tried to derive a share but input shares had inconsistent seed IDs";
case MISMATCH_LENGTH: return "tried to derive a share but input shares had inconsistent lengths";
}
assert(0);
}
/** Encode a codex32 string. */
std::string Result::Encode() const {
assert(IsValid());

View File

@ -41,6 +41,8 @@ enum Error {
MISMATCH_LENGTH,
};
std::string ErrorString(Error e);
class Result
{
public: