|
3 | 3 | // Portions Copyright (c) Microsoft Corporation. All rights reserved. |
4 | 4 | // See LICENSE file in the project root for full license information. |
5 | 5 | // |
6 | | -#include "CorLib.h" |
7 | | - |
8 | | -// |
9 | | -// Generate a new GUID |
10 | | -// |
11 | | -// Based on the version 4 GUID (random) |
12 | | -// http://guid.one/guid/make |
13 | 6 |
|
| 7 | +#include "CorLib.h" |
14 | 8 |
|
15 | | -HRESULT Library_corlib_native_System_Guid::GenerateNewGuid___STATIC__SZARRAY_U1( CLR_RT_StackFrame& stack ) |
| 9 | +HRESULT Library_corlib_native_System_Guid::GenerateNewGuid___STATIC__SZARRAY_U1(CLR_RT_StackFrame &stack) |
16 | 10 | { |
17 | 11 | NANOCLR_HEADER(); |
18 | 12 |
|
19 | | - CLR_RT_Random rand; |
20 | | - CLR_UINT8* buf; |
21 | | - CLR_RT_HeapBlock& top = stack.PushValueAndClear(); |
22 | | - |
| 13 | + CLR_RT_Random rand; |
| 14 | + CLR_UINT8 *buf; |
| 15 | + CLR_RT_HeapBlock &top = stack.PushValueAndClear(); |
| 16 | + |
23 | 17 | // Create a array of 16 bytes on top of stack to return |
24 | | - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, 16, g_CLR_RT_WellKnownTypes.m_UInt8 )); |
| 18 | + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, 16, g_CLR_RT_WellKnownTypes.m_UInt8)); |
25 | 19 | buf = top.DereferenceArray()->GetFirstElement(); |
26 | 20 |
|
27 | 21 | rand.Initialize(); |
28 | | - rand.NextBytes(buf, 16); // fill with random numbers |
29 | 22 |
|
30 | | - buf[7] = (buf[7] & 0x0f) | 0x40; // Set verion |
31 | | - buf[9] = (buf[7] & 0x3f) | 0x80; // Set variant |
32 | | - |
| 23 | + // Generate 16 random bytes for the GUID |
| 24 | + rand.NextBytes(buf, 16); |
| 25 | + |
| 26 | + // Set the version (version 4, bits 12-15 of time_hi_and_version) |
| 27 | + buf[7] = (buf[7] & 0x0F) | 0x40; |
| 28 | + |
| 29 | + // Set the variant (the two most significant bits of clock_seq_hi_and_reserved must be 10) |
| 30 | + buf[8] = (buf[8] & 0x3F) | 0x80; |
| 31 | + |
33 | 32 | NANOCLR_NOCLEANUP(); |
34 | 33 | } |
0 commit comments