diff options
Diffstat (limited to 'cast/sender/channel')
-rw-r--r-- | cast/sender/channel/cast_auth_util.cc | 15 | ||||
-rw-r--r-- | cast/sender/channel/cast_auth_util.h | 3 |
2 files changed, 18 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() {} diff --git a/cast/sender/channel/cast_auth_util.h b/cast/sender/channel/cast_auth_util.h index d23ebd7e..9c0646ec 100644 --- a/cast/sender/channel/cast_auth_util.h +++ b/cast/sender/channel/cast_auth_util.h @@ -36,6 +36,9 @@ class AuthContext { // The same context must be used in the challenge and reply. static AuthContext Create(); + // Create a context with some seed nonce data for testing. + static AuthContext CreateForTest(const std::string& nonce_data); + // Verifies the nonce received in the response is equivalent to the one sent. // Returns success if |nonce_response| matches nonce_ Error VerifySenderNonce(const std::string& nonce_response, |