Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2781)

Unified Diff: base/guid.h

Issue 1906723003: Unify UUID/GUID generation code across base and blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove ASSERT, use StringPiece Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/guid.h
diff --git a/base/guid.h b/base/guid.h
index c0a06f8858e3637aace7ebd03287e18b095e35e4..29c24eacefe67fa499dfc0e85a657df721e043df 100644
--- a/base/guid.h
+++ b/base/guid.h
@@ -10,23 +10,33 @@
#include <string>
#include "base/base_export.h"
+#include "base/strings/string_piece.h"
#include "build/build_config.h"
namespace base {
-// Generate a 128-bit random GUID of the form: "%08X-%04X-%04X-%04X-%012llX".
+// Generate a 128-bit (pseudo) random GUID in the form of version 4 as described
+// in RFC 4122, section 4.4.
+// The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
+// where y is one of [8, 9, A, B].
+// The hexadecimal values "a" through "f" are output as lower case characters.
// If GUID generation fails an empty string is returned.
-// The POSIX implementation uses pseudo random number generation to create
-// the GUID. The Windows implementation uses system services.
BASE_EXPORT std::string GenerateGUID();
-// Returns true if the input string conforms to the GUID format.
-BASE_EXPORT bool IsValidGUID(const std::string& guid);
+// Returns true if the input string conforms to the version 4 GUID format.
+// Note that this does NOT check if the hexadecimal values "a" through "f"
+// are in lower case characters, as Version 4 RFC says onput they're
+// case insensitive. (Use IsValidGUIDOutputString for checking if the
+// given string is valid output string)
+BASE_EXPORT bool IsValidGUID(const base::StringPiece& guid);
+
+// Returns true if the input string is valid version 4 GUID output string.
+// This also checks if the hexadecimal values "a" through "f" are in lower
+// case characters.
+BASE_EXPORT bool IsValidGUIDOutputString(const base::StringPiece& guid);
-#if defined(OS_POSIX)
// For unit testing purposes only. Do not use outside of tests.
BASE_EXPORT std::string RandomDataToGUIDString(const uint64_t bytes[2]);
-#endif
} // namespace base
« no previous file with comments | « base/base.gypi ('k') | base/guid.cc » ('j') | third_party/WebKit/Source/platform/UUID.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698