aboutsummaryrefslogtreecommitdiff
path: root/cast/sender/channel/cast_auth_util.cc
diff options
context:
space:
mode:
authorbtolsch <btolsch@chromium.org>2021-07-26 15:03:56 -0700
committerOpenscreen LUCI CQ <openscreen-scoped@luci-project-accounts.iam.gserviceaccount.com>2021-07-26 23:22:23 +0000
commit03ca0440e6bd18f7c3588056ed7c251f63e15c4e (patch)
tree93d69a5b16542435947a802b8dc2cf556aeffece /cast/sender/channel/cast_auth_util.cc
parentf9715c5369c7dca34da0cb7b416efe65ed52a474 (diff)
downloadopenscreen-03ca0440e6bd18f7c3588056ed7c251f63e15c4e.tar.gz
Add AuthContext::CreateForTest for fuzzer
This change adds the ability for tests to create an AuthContext using a fixed data string for the nonce. This is to facilitate reproducibility of fuzz tests and is a direct copy of the existing upstream version. Bug: b/185815206 Change-Id: Ifef4e4cca641e6113356e5818bed2006e814a4de Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/3053623 Reviewed-by: Ryan Keane <rwkeane@google.com> Commit-Queue: Brandon Tolsch <btolsch@chromium.org>
Diffstat (limited to 'cast/sender/channel/cast_auth_util.cc')
-rw-r--r--cast/sender/channel/cast_auth_util.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/cast/sender/channel/cast_auth_util.cc b/cast/sender/channel/cast_auth_util.cc
index 6e9cf626..f0e1c36f 100644
--- a/cast/sender/channel/cast_auth_util.cc
+++ b/cast/sender/channel/cast_auth_util.cc
@@ -184,6 +184,21 @@ AuthContext AuthContext::Create() {
return AuthContext(CastNonce::Get());
}
+// static
+AuthContext AuthContext::CreateForTest(const std::string& nonce_data) {
+ std::string nonce;
+ if (nonce_data.empty()) {
+ nonce = std::string(kNonceSizeInBytes, '0');
+ } else {
+ while (nonce.size() < kNonceSizeInBytes) {
+ nonce += nonce_data;
+ }
+ nonce.erase(kNonceSizeInBytes);
+ }
+ OSP_DCHECK_EQ(nonce.size(), kNonceSizeInBytes);
+ return AuthContext(nonce);
+}
+
AuthContext::AuthContext(const std::string& nonce) : nonce_(nonce) {}
AuthContext::~AuthContext() {}