Add tiny CBOR parser

This commit is contained in:
Alex Beregszaszi
2019-03-11 13:01:37 +01:00
parent 12f34c8229
commit 61220eb3e0
2 changed files with 125 additions and 0 deletions
+13
View File
@@ -20,6 +20,10 @@
*/
#include <libdevcore/CommonData.h>
#include <boost/optional.hpp>
#include <map>
#include <string>
namespace dev
@@ -37,6 +41,15 @@ bytes bytecodeSansMetadata(bytes const& _bytecode);
/// Throws exception on invalid hex string.
std::string bytecodeSansMetadata(std::string const& _bytecode);
/// Parse CBOR metadata into a map. Expects the input CBOR to be a
/// fixed length map, with each key being a string. The values
/// are parsed as follows:
/// - strings into strings
/// - bytes into hex strings
/// - booleans into "true"/"false" strings
/// - everything else is invalid
boost::optional<std::map<std::string, std::string>> parseCBORMetadata(bytes const& _metadata);
/// Expects a serialised metadata JSON and returns true if the
/// content is valid metadata.
bool isValidMetadata(std::string const& _metadata);