aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-08-05 16:33:07 +0200
committerGitHub <noreply@github.com>2020-08-05 16:33:07 +0200
commitb91dc7ebad733f557dd812f285095b700c267fa2 (patch)
tree09384943f4f199315cf166bda60a4948918b3c50 /src/libutil/hash.hh
parent75f220a59570e4de58914fa60b0deefe5d06058c (diff)
parentd3452a5ed6e7f052aad5e7fd9aaa1061b0c54652 (diff)
Merge pull request #3730 from obsidiansystems/better-ca-parse-errors
Improve hash parsing and errors
Diffstat (limited to 'src/libutil/hash.hh')
-rw-r--r--src/libutil/hash.hh26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh
index abcd58f24..00ce7bb6f 100644
--- a/src/libutil/hash.hh
+++ b/src/libutil/hash.hh
@@ -34,21 +34,31 @@ struct Hash
HashType type;
/* Create a zero-filled hash object. */
- Hash(HashType type) : type(type) { init(); };
+ Hash(HashType type);
- /* Initialize the hash from a string representation, in the format
+ /* Parse the hash from a string representation in the format
"[<type>:]<base16|base32|base64>" or "<type>-<base64>" (a
Subresource Integrity hash expression). If the 'type' argument
is not present, then the hash type must be specified in the
string. */
- Hash(std::string_view s, std::optional<HashType> type);
- // type must be provided
- Hash(std::string_view s, HashType type);
- // hash type must be part of string
- Hash(std::string_view s);
+ static Hash parseAny(std::string_view s, std::optional<HashType> type);
- void init();
+ /* Parse a hash from a string representation like the above, except the
+ type prefix is mandatory is there is no separate arguement. */
+ static Hash parseAnyPrefixed(std::string_view s);
+ /* Parse a plain hash that musst not have any prefix indicating the type.
+ The type is passed in to disambiguate. */
+ static Hash parseNonSRIUnprefixed(std::string_view s, HashType type);
+
+ static Hash parseSRI(std::string_view original);
+
+private:
+ /* The type must be provided, the string view must not include <type>
+ prefix. `isSRI` helps disambigate the various base-* encodings. */
+ Hash(std::string_view s, HashType type, bool isSRI);
+
+public:
/* Check whether a hash is set. */
operator bool () const { return (bool) type; }