Skip to content

Commit 8d2b2b6

Browse files
committed
add entrophysource support to hyperdrive
1 parent 789db95 commit 8d2b2b6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/workerd/api/hyperdrive.c++

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@
1313
#include <kj/string.h>
1414

1515
namespace workerd::api {
16-
Hyperdrive::Hyperdrive(
17-
uint clientIndex, kj::String database, kj::String user, kj::String password, kj::String scheme)
16+
Hyperdrive::Hyperdrive(uint clientIndex,
17+
kj::String database,
18+
kj::String user,
19+
kj::String password,
20+
kj::String scheme,
21+
const kj::Maybe<kj::EntropySource&>& maybeEntropySource)
1822
: clientIndex(clientIndex),
1923
database(kj::mv(database)),
2024
user(kj::mv(user)),
2125
password(kj::mv(password)),
2226
scheme(kj::mv(scheme)) {
2327
kj::byte randomBytes[16]{};
24-
KJ_ASSERT(RAND_bytes(randomBytes, sizeof(randomBytes)) == 1);
28+
KJ_IF_SOME(entrophySource, maybeEntropySource) {
29+
entrophySource.generate(kj::arrayPtr(randomBytes, sizeof(randomBytes)));
30+
} else {
31+
KJ_ASSERT(RAND_bytes(randomBytes, sizeof(randomBytes)) == 1);
32+
}
2533
randomHost = kj::str(kj::encodeHex(randomBytes), ".hyperdrive.local");
2634
}
2735

src/workerd/api/hyperdrive.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <workerd/jsg/jsg.h>
88

9+
#include <kj/compat/http.h>
10+
911
namespace kj {
1012
class AsyncIoStream;
1113
}
@@ -26,7 +28,8 @@ class Hyperdrive: public jsg::Object {
2628
kj::String database,
2729
kj::String user,
2830
kj::String password,
29-
kj::String scheme);
31+
kj::String scheme,
32+
const kj::Maybe<kj::EntropySource&>& = kj::none);
3033
jsg::Ref<Socket> connect(jsg::Lock& js);
3134
kj::StringPtr getDatabase();
3235
kj::StringPtr getUser();

0 commit comments

Comments
 (0)