From e3c5ada3a70f71fe117319cd335a4462387c744d Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 5 Aug 2014 09:56:49 -0700 Subject: Add signatures to Dictionary, and fix unhex() API in Utils to be a little safer. --- node/Utils.hpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'node/Utils.hpp') diff --git a/node/Utils.hpp b/node/Utils.hpp index 4298d045..bafe0b39 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -145,11 +145,12 @@ public: * This ignores all non-hex characters, just stepping over them and * continuing. Upper and lower case are supported for letters a-f. * - * @param hex Hexadecimal ASCII code (non-hex chars are ignored) + * @param hex Hexadecimal ASCII code (non-hex chars are ignored, stops at zero or maxlen) + * @param maxlen Maximum length of hex string buffer * @return Binary data */ - static std::string unhex(const char *hex); - static inline std::string unhex(const std::string &hex) { return unhex(hex.c_str()); } + static std::string unhex(const char *hex,unsigned int maxlen); + static inline std::string unhex(const std::string &hex) { return unhex(hex.c_str(),(unsigned int)hex.length()); } /** * Convert hexadecimal to binary data @@ -158,26 +159,13 @@ public: * continuing. Upper and lower case are supported for letters a-f. * * @param hex Hexadecimal ASCII + * @param maxlen Maximum length of hex string buffer * @param buf Buffer to fill * @param len Length of buffer * @return Number of characters actually written */ - static unsigned int unhex(const char *hex,void *buf,unsigned int len); - static inline unsigned int unhex(const std::string &hex,void *buf,unsigned int len) { return unhex(hex.c_str(),buf,len); } - - /** - * Convert hexadecimal to binary data - * - * This ignores all non-hex characters, just stepping over them and - * continuing. Upper and lower case are supported for letters a-f. - * - * @param hex Hexadecimal ASCII - * @param hexlen Length of hex ASCII - * @param buf Buffer to fill - * @param len Length of buffer - * @return Number of bytes actually written to buffer - */ - static unsigned int unhex(const char *hex,unsigned int hexlen,void *buf,unsigned int len); + static unsigned int unhex(const char *hex,unsigned int maxlen,void *buf,unsigned int len); + static inline unsigned int unhex(const std::string &hex,void *buf,unsigned int len) { return unhex(hex.c_str(),hex.length(),buf,len); } /** * Generate secure random bytes -- cgit v1.2.3