summaryrefslogtreecommitdiff
path: root/node/Utils.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-04 12:24:21 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-04 12:24:21 -0400
commitea4e1136dd8b8d7830f770b4dff92f4946a998dd (patch)
treeb965512eaf04205a5b209b7ff160d5650d1ccd31 /node/Utils.cpp
parentca6c0fad081b48a7316e412675aa8bd30d9a0540 (diff)
downloadinfinitytier-ea4e1136dd8b8d7830f770b4dff92f4946a998dd.tar.gz
infinitytier-ea4e1136dd8b8d7830f770b4dff92f4946a998dd.zip
Flesh out membership certificate with signature, better serialize/deserialize, and rename parameter to qualifier to make better conceptual sense.
Diffstat (limited to 'node/Utils.cpp')
-rw-r--r--node/Utils.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/node/Utils.cpp b/node/Utils.cpp
index 31174ecc..cf5519cb 100644
--- a/node/Utils.cpp
+++ b/node/Utils.cpp
@@ -283,6 +283,37 @@ unsigned int Utils::unhex(const char *hex,void *buf,unsigned int len)
return l;
}
+unsigned int Utils::unhex(const char *hex,unsigned int hexlen,void *buf,unsigned int len)
+ throw()
+{
+ int n = 1;
+ unsigned char c,b = 0;
+ unsigned int l = 0;
+ const char *const end = hex + hexlen;
+
+ while (hex != end) {
+ c = (unsigned char)*(hex++);
+ if ((c >= 48)&&(c <= 57)) { // 0..9
+ if ((n ^= 1)) {
+ if (l >= len) break;
+ ((unsigned char *)buf)[l++] = (b | (c - 48));
+ } else b = (c - 48) << 4;
+ } else if ((c >= 65)&&(c <= 70)) { // A..F
+ if ((n ^= 1)) {
+ if (l >= len) break;
+ ((unsigned char *)buf)[l++] = (b | (c - (65 - 10)));
+ } else b = (c - (65 - 10)) << 4;
+ } else if ((c >= 97)&&(c <= 102)) { // a..f
+ if ((n ^= 1)) {
+ if (l >= len) break;
+ ((unsigned char *)buf)[l++] = (b | (c - (97 - 10)));
+ } else b = (c - (97 - 10)) << 4;
+ }
+ }
+
+ return l;
+}
+
void Utils::getSecureRandom(void *buf,unsigned int bytes)
{
static Mutex randomLock;