Export media_cas_proxy_sdk
This commit is contained in:
31
util/random/BUILD
Normal file
31
util/random/BUILD
Normal file
@@ -0,0 +1,31 @@
|
||||
################################################################################
|
||||
# Copyright 2017 Google LLC.
|
||||
#
|
||||
# This software is licensed under the terms defined in the Widevine Master
|
||||
# License Agreement. For a copy of this agreement, please contact
|
||||
# widevine-licensing@google.com.
|
||||
################################################################################
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "global_id",
|
||||
hdrs = [
|
||||
"global_id.h",
|
||||
],
|
||||
deps = [
|
||||
"//external:openssl",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "global_id_test",
|
||||
srcs = ["global_id_test.cc"],
|
||||
deps = [
|
||||
":global_id",
|
||||
"//base",
|
||||
"//testing:gunit_main",
|
||||
],
|
||||
)
|
||||
30
util/random/global_id.h
Normal file
30
util/random/global_id.h
Normal file
@@ -0,0 +1,30 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2017 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef UTIL_RANDOM_GLOBAL_ID_H_
|
||||
#define UTIL_RANDOM_GLOBAL_ID_H_
|
||||
|
||||
#include "openssl/rand.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace util {
|
||||
namespace random {
|
||||
|
||||
static uint64_t NewGlobalID() {
|
||||
static __thread uint64_t val = 0;
|
||||
if (val == 0) {
|
||||
RAND_bytes(reinterpret_cast<uint8_t*>(&val), sizeof(val));
|
||||
}
|
||||
return val++;
|
||||
}
|
||||
|
||||
} // namespace random
|
||||
} // namespace util
|
||||
} // namespace widevine
|
||||
|
||||
#endif // UTIL_RANDOM_GLOBAL_ID_H_
|
||||
27
util/random/global_id_test.cc
Normal file
27
util/random/global_id_test.cc
Normal file
@@ -0,0 +1,27 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2017 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "util/random/global_id.h"
|
||||
|
||||
#include "glog/logging.h"
|
||||
#include "testing/gunit.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace util {
|
||||
namespace random {
|
||||
|
||||
TEST(GlobalIDTest, NewGlobalID) {
|
||||
uint64_t id = NewGlobalID();
|
||||
LOG(INFO) << "NewGlobalID " << id;
|
||||
EXPECT_EQ(id + 1, NewGlobalID());
|
||||
EXPECT_EQ(id + 2, NewGlobalID());
|
||||
}
|
||||
|
||||
} // namespace random
|
||||
} // namespace util
|
||||
} // namespace widevine
|
||||
Reference in New Issue
Block a user