aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2015-09-09 14:24:56 +0200
committerMarcoFalke <falke.marco@gmail.com>2015-09-16 15:23:29 +0200
commit1c1b1b315f2f89584abe9a7558945dea2fbee708 (patch)
tree80c5e16ed073213d4645f88eb42c398ed194c27f /src/utilstrencodings.h
parent536207f3167daad1fa3d60a1de7d9cb55db28ac9 (diff)
[uacomment] Sanitize per BIP-0014
* SanitizeString() can be requested to be more strict * Throw error when SanitizeString() changes uacomments * Fix tests
Diffstat (limited to 'src/utilstrencodings.h')
-rw-r--r--src/utilstrencodings.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h
index dcd56751f2..ce93e83497 100644
--- a/src/utilstrencodings.h
+++ b/src/utilstrencodings.h
@@ -22,7 +22,21 @@
/** This is needed because the foreach macro can't get over the comma in pair<t1, t2> */
#define PAIRTYPE(t1, t2) std::pair<t1, t2>
-std::string SanitizeString(const std::string& str);
+/** Used by SanitizeString() */
+enum SafeChars
+{
+ SAFE_CHARS_DEFAULT, //!< The full set of allowed chars
+ SAFE_CHARS_UA_COMMENT //!< BIP-0014 subset
+};
+
+/**
+* Remove unsafe chars. Safe chars chosen to allow simple messages/URLs/email
+* addresses, but avoid anything even possibly remotely dangerous like & or >
+* @param[in] str The string to sanitize
+* @param[in] rule The set of safe chars to choose (default: least restrictive)
+* @return A new string without unsafe chars
+*/
+std::string SanitizeString(const std::string& str, int rule = SAFE_CHARS_DEFAULT);
std::vector<unsigned char> ParseHex(const char* psz);
std::vector<unsigned char> ParseHex(const std::string& str);
signed char HexDigit(char c);