summaryrefslogtreecommitdiff
path: root/libs/binder/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/binder/Utils.cpp')
-rw-r--r--libs/binder/Utils.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/libs/binder/Utils.cpp b/libs/binder/Utils.cpp
index d2a5be1102..b0289a7196 100644
--- a/libs/binder/Utils.cpp
+++ b/libs/binder/Utils.cpp
@@ -16,6 +16,7 @@
#include "Utils.h"
+#include <android-base/file.h>
#include <string.h>
using android::base::ErrnoError;
@@ -38,4 +39,17 @@ Result<void> setNonBlocking(android::base::borrowed_fd fd) {
return {};
}
+status_t getRandomBytes(uint8_t* data, size_t size) {
+ int ret = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
+ if (ret == -1) {
+ return -errno;
+ }
+
+ base::unique_fd fd(ret);
+ if (!base::ReadFully(fd, data, size)) {
+ return -errno;
+ }
+ return OK;
+}
+
} // namespace android