Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/rand_util.h" | |
| 6 | |
| 7 #include <stdlib.h> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "ppapi/c/dev/ppb_crypto_dev.h" | |
| 12 #include "ppapi/cpp/module.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 class PepperCrypto { | |
| 17 public: | |
| 18 PepperCrypto() { | |
| 19 ppb_crypto_ = reinterpret_cast<const PPB_Crypto_Dev*>( | |
| 20 pp::Module::Get()->GetPluginInterface(PPB_CRYPTO_DEV_INTERFACE)); | |
|
bradn
2012/07/24 23:02:29
Two questions:
1. I had the impression this interf
| |
| 21 DCHECK(ppb_crypto_); | |
| 22 } | |
| 23 | |
| 24 ~PepperCrypto() { | |
| 25 } | |
| 26 | |
| 27 void GetRandomBytes(char* buffer, uint32_t num_bytes) { | |
| 28 ppb_crypto_->GetRandomBytes(buffer, num_bytes); | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 const PPB_Crypto_Dev* ppb_crypto_; | |
| 33 }; | |
| 34 | |
| 35 base::LazyInstance<PepperCrypto> g_pepper_crypto = LAZY_INSTANCE_INITIALIZER; | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 namespace base { | |
| 40 | |
| 41 uint64 RandUint64() { | |
| 42 uint64 result; | |
| 43 g_pepper_crypto.Pointer()->GetRandomBytes( | |
| 44 reinterpret_cast<char*>(&result), sizeof(result)); | |
| 45 return result; | |
| 46 } | |
| 47 | |
| 48 } // namespace base | |
| OLD | NEW |