merge fix for #878

This commit is contained in:
Guenter Obiltschnig
2015-07-31 12:17:20 +02:00
parent 5781bcbe35
commit e4dcb85c1f
6 changed files with 116 additions and 20 deletions

View File

@@ -127,6 +127,7 @@ void UUID::parse(const std::string& uuid)
throw SyntaxException(uuid);
}
bool UUID::tryParse(const std::string& uuid)
{
if (uuid.size() < 32)
@@ -141,35 +142,50 @@ bool UUID::tryParse(const std::string& uuid)
return false;
}
UUID newUUID;
std::string::const_iterator it = uuid.begin();
_timeLow = 0;
newUUID._timeLow = 0;
for (int i = 0; i < 8; ++i)
{
_timeLow = (_timeLow << 4) | nibble(*it++);
Int16 n = nibble(*it++);
if (n < 0) return false;
newUUID._timeLow = (newUUID._timeLow << 4) | n;
}
if (haveHyphens) ++it;
_timeMid = 0;
newUUID._timeMid = 0;
for (int i = 0; i < 4; ++i)
{
_timeMid = (_timeMid << 4) | nibble(*it++);
Int16 n = nibble(*it++);
if (n < 0) return false;
newUUID._timeMid = (newUUID._timeMid << 4) | n;
}
if (haveHyphens) ++it;
_timeHiAndVersion = 0;
newUUID._timeHiAndVersion = 0;
for (int i = 0; i < 4; ++i)
{
_timeHiAndVersion = (_timeHiAndVersion << 4) | nibble(*it++);
Int16 n = nibble(*it++);
if (n < 0) return false;
newUUID._timeHiAndVersion = (newUUID._timeHiAndVersion << 4) | n;
}
if (haveHyphens) ++it;
_clockSeq = 0;
newUUID._clockSeq = 0;
for (int i = 0; i < 4; ++i)
{
_clockSeq = (_clockSeq << 4) | nibble(*it++);
Int16 n = nibble(*it++);
if (n < 0) return false;
newUUID._clockSeq = (newUUID._clockSeq << 4) | n;
}
if (haveHyphens) ++it;
for (int i = 0; i < 6; ++i)
{
_node[i] = (nibble(*it++) << 4) | nibble(*it++) ;
Int16 n1 = nibble(*it++);
if (n1 < 0) return false;
Int16 n2 = nibble(*it++);
if (n2 < 0) return false;
newUUID._node[i] = (n1 << 4) | n2;
}
swap(newUUID);
return true;
}
@@ -282,16 +298,16 @@ void UUID::appendHex(std::string& str, UInt32 n)
}
UInt8 UUID::nibble(char hex)
Int16 UUID::nibble(char hex)
{
if (hex >= 'a' && hex <= 'f')
return UInt8(hex - 'a' + 10);
return hex - 'a' + 10;
else if (hex >= 'A' && hex <= 'F')
return UInt8(hex - 'A' + 10);
return hex - 'A' + 10;
else if (hex >= '0' && hex <= '9')
return UInt8(hex - '0');
return hex - '0';
else
return UInt8(0);
return -1;
}

View File

@@ -19,6 +19,7 @@
#include "Poco/RandomStream.h"
#include "Poco/DigestEngine.h"
#include "Poco/MD5Engine.h"
#include "Poco/SHA1Engine.h"
#include "Poco/SingletonHolder.h"
#include <cstring>
@@ -62,6 +63,14 @@ UUID UUIDGenerator::createFromName(const UUID& nsid, const std::string& name)
UUID UUIDGenerator::createFromName(const UUID& nsid, const std::string& name, DigestEngine& de)
{
UUID::Version version = UUID::UUID_NAME_BASED;
if (dynamic_cast<SHA1Engine*>(&de)) version = UUID::UUID_NAME_BASED_SHA1;
return createFromName(nsid, name, de, version);
}
UUID UUIDGenerator::createFromName(const UUID& nsid, const std::string& name, DigestEngine& de, UUID::Version version)
{
poco_assert_dbg (de.digestLength() >= 16);
@@ -80,7 +89,7 @@ UUID UUIDGenerator::createFromName(const UUID& nsid, const std::string& name, Di
{
buffer[i] = d[i];
}
return UUID(buffer, UUID::UUID_NAME_BASED);
return UUID(buffer, version);
}