Revert "sal: remove rtl_createNamedUuid"
it breaks the published API
This reverts commit 3bad9e2daa.
Change-Id: If6f0b7f8d4a52415bd9fdacde20d9ec1643f590e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209384
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
@@ -84,6 +84,49 @@ SAL_DLLPUBLIC void SAL_CALL rtl_createUuid(
|
||||
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_compareUuid(
|
||||
const sal_uInt8 *pUUID1 , const sal_uInt8 *pUUID2 );
|
||||
|
||||
/** Creates named UUIDs.
|
||||
|
||||
<p>
|
||||
The version 3 UUID is meant for generating UUIDs from <em>names</em> that
|
||||
are drawn from, and unique within, some <em>name space</em>. Some examples
|
||||
of names (and, implicitly, name spaces) might be DNS names, URLs, ISO
|
||||
Object IDs (OIDs), reserved words in a programming language, or X.500
|
||||
Distinguished Names (DNs); thus, the concept of name and name space
|
||||
should be broadly construed, and not limited to textual names.
|
||||
|
||||
<p>
|
||||
The requirements for such UUIDs are as follows:
|
||||
|
||||
<ul>
|
||||
<li> The UUIDs generated at different times from the same name in the
|
||||
same namespace MUST be equal
|
||||
|
||||
<li> The UUIDs generated from two different names in the same namespace
|
||||
should be different (with very high probability)
|
||||
|
||||
<li> The UUIDs generated from the same name in two different namespaces
|
||||
should be different with (very high probability)
|
||||
|
||||
<li> If two UUIDs that were generated from names are equal, then they
|
||||
were generated from the same name in the same namespace (with very
|
||||
high probability).
|
||||
</ul>
|
||||
|
||||
@param pTargetUUID pointer to at least 16 bytes of memory. After the call
|
||||
it contains the newly generated uuid in network byte order.
|
||||
@param pNameSpaceUUID The namespace uuid. Below are some predefined ones,
|
||||
but any arbitrary uuid can be used as namespace.
|
||||
|
||||
@param pName the name
|
||||
*/
|
||||
SAL_DLLPUBLIC void SAL_CALL rtl_createNamedUuid(
|
||||
sal_uInt8 *pTargetUUID,
|
||||
const sal_uInt8 *pNameSpaceUUID,
|
||||
const rtl_String *pName
|
||||
);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Predefined Namespaces
|
||||
(Use them the following way : sal_uInt8 aNsDNS[16]) = RTL_UUID_NAMESPACE_DNS;
|
||||
|
||||
@@ -95,7 +95,57 @@ public:
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
}; // class createUuid
|
||||
|
||||
class createNamedUuid : public CppUnit::TestFixture
|
||||
{
|
||||
public:
|
||||
void createNamedUuid_001()
|
||||
{
|
||||
sal_uInt8 NameSpace_DNS[16] = RTL_UUID_NAMESPACE_DNS;
|
||||
sal_uInt8 NameSpace_URL[16] = RTL_UUID_NAMESPACE_URL;
|
||||
sal_uInt8 pPriorCalculatedUUID[16] = {
|
||||
0x52,0xc9,0x30,0xa5,
|
||||
0xd1,0x61,0x3b,0x16,
|
||||
0x98,0xc5,0xf8,0xd1,
|
||||
0x10,0x10,0x6d,0x4d };
|
||||
|
||||
sal_uInt8 pNamedUUID[16], pNamedUUID2[16];
|
||||
|
||||
// Same name does generate the same uuid
|
||||
rtl_String *pName = nullptr;
|
||||
rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Name" );
|
||||
rtl_createNamedUuid( pNamedUUID , NameSpace_DNS , pName );
|
||||
rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
|
||||
CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pNamedUUID2 , 16 ));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Same name should generate the same uuid", sal_Int32(0), rtl_compareUuid( pNamedUUID , pNamedUUID2 ) );
|
||||
CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pPriorCalculatedUUID , 16 ) );
|
||||
|
||||
// Different names does not generate the same uuid
|
||||
rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Namf" );
|
||||
rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
|
||||
CPPUNIT_ASSERT_MESSAGE("Different names does not generate the same uuid.", memcmp( pNamedUUID , pNamedUUID2 , 16 ) );
|
||||
|
||||
// the same name with different namespace uuid produces different uuids
|
||||
rtl_createNamedUuid( pNamedUUID , NameSpace_URL , pName );
|
||||
CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", memcmp( pNamedUUID , pNamedUUID2 , 16 ));
|
||||
CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", rtl_compareUuid( pNamedUUID , pNamedUUID2 ) != 0);
|
||||
|
||||
//test compareUuid
|
||||
if ( rtl_compareUuid( pNamedUUID , pNamedUUID2 ) > 0 )
|
||||
{ CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) < 0);
|
||||
}
|
||||
else
|
||||
CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) > 0);
|
||||
|
||||
rtl_string_release( pName );
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_SUITE(createNamedUuid);
|
||||
CPPUNIT_TEST(createNamedUuid_001);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
}; // class createNamedUuid
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createUuid);
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createNamedUuid);
|
||||
} // namespace rtl_Uuid
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -22,6 +22,14 @@
|
||||
|
||||
#include <rtl/random.h>
|
||||
#include <rtl/uuid.h>
|
||||
#include <rtl/digest.h>
|
||||
|
||||
#define SWAP_INT16_TO_NETWORK(x)\
|
||||
{ sal_uInt16 y = x;\
|
||||
sal_uInt8 *p = reinterpret_cast<sal_uInt8 *>(&(x)); \
|
||||
p[0] = static_cast<sal_uInt8>( ( y >> 8 ) & 0xff );\
|
||||
p[1] = static_cast<sal_uInt8>( ( y ) & 0xff);\
|
||||
}
|
||||
|
||||
#define SWAP_NETWORK_TO_INT16(x)\
|
||||
{ sal_uInt16 y = x;\
|
||||
@@ -52,6 +60,25 @@ struct UUID
|
||||
|
||||
}
|
||||
|
||||
static void write_v3( sal_uInt8 *pUuid )
|
||||
{
|
||||
UUID uuid;
|
||||
// copy to avoid alignment problems
|
||||
memcpy(&uuid, pUuid, 16);
|
||||
|
||||
SWAP_NETWORK_TO_INT16(uuid.time_hi_and_version);
|
||||
|
||||
/* put in the variant and version bits */
|
||||
uuid.time_hi_and_version &= 0x0FFF;
|
||||
uuid.time_hi_and_version |= (3 << 12);
|
||||
uuid.clock_seq_hi_and_reserved &= 0x3F;
|
||||
uuid.clock_seq_hi_and_reserved |= 0x80;
|
||||
|
||||
SWAP_INT16_TO_NETWORK(uuid.time_hi_and_version);
|
||||
|
||||
memcpy(pUuid, &uuid, 16);
|
||||
}
|
||||
|
||||
extern "C" void SAL_CALL rtl_createUuid(sal_uInt8 *pTargetUUID ,
|
||||
SAL_UNUSED_PARAMETER const sal_uInt8 *,
|
||||
SAL_UNUSED_PARAMETER sal_Bool)
|
||||
@@ -70,6 +97,21 @@ extern "C" void SAL_CALL rtl_createUuid(sal_uInt8 *pTargetUUID ,
|
||||
pTargetUUID[8] |= 0x80;
|
||||
}
|
||||
|
||||
extern "C" void SAL_CALL rtl_createNamedUuid(sal_uInt8 *pTargetUUID,
|
||||
const sal_uInt8 *pNameSpaceUUID,
|
||||
const rtl_String *pName )
|
||||
{
|
||||
rtlDigest digest = rtl_digest_createMD5();
|
||||
|
||||
rtl_digest_updateMD5(digest, pNameSpaceUUID, 16);
|
||||
rtl_digest_updateMD5(digest, pName->buffer, pName->length);
|
||||
|
||||
rtl_digest_getMD5(digest, pTargetUUID, 16);
|
||||
rtl_digest_destroyMD5(digest);
|
||||
|
||||
write_v3(pTargetUUID);
|
||||
}
|
||||
|
||||
extern "C" sal_Int32 SAL_CALL rtl_compareUuid(const sal_uInt8 *pUUID1, const sal_uInt8 *pUUID2)
|
||||
{
|
||||
int i;
|
||||
|
||||
Reference in New Issue
Block a user