uuid_generate_random (libuuid) on solaris

泄露秘密 提交于 2019-12-12 09:46:30

问题


I have a simple C++ function that calls "uuid_generate_random". It seems the generated UUID is not standard compliant (UUID Version 4). Any Ideas?

The code I am using is (uuid_generate_random & uuid_unparse functions are available in libuuid):

char uuidBuff[36];
uuid_t uuidGenerated;
uuid_generate_random(uuidGenerated);
uuid_unparse(uuidGenerated, uuidBuff);

I understand that "uuid_generate_random" generates the UUID version 4, however, the string that is being returned is like:

Run1) 2e9dc3c5-426a-eea0-8186-f6b65b5dc361 
Run2) 112c6a78-51bc-cbbb-ae9c-92a33e1fd95f 
Run3) 5abd3d6d-0259-ce5c-8428-a51bacc04c0f 
Run4) 66a22485-7e5f-e5c2-a317-c1b295bf124f

It appears that it is returning random characters for the whole string. The definition from wikipedia, it should be in the form of:

xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with any hexadecimal digits for x but only one of 8, 9, A, or B for y.

Any input will be greatly appreciated.

Regards Daniel


回答1:


You're quite correct that libuuid seems not to be adhering to the ITU recommendation... It could be argued that the recommendation itself is overly pedantic about retaining version information, as it serves little purpose beyond allowing technorati to easily distinguish how the UUID was generated, but that's beside the point.

The good news is that, if you care to, you can easily make these into conformant UUIDs through the simple expedient of smashing in the right version bits. :-)



来源:https://stackoverflow.com/questions/3759410/uuid-generate-random-libuuid-on-solaris

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!