Skip to content

Commit 3ac1da9

Browse files
trondndaverigby
authored andcommitted
Cleanup: fix warnings from clang-tidy in SCRAM-SHA
Change-Id: If625985179b4a8ad43716c0f6227bb1877c4cca6 Reviewed-on: http://review.couchbase.org/111950 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 4eab7f9 commit 3ac1da9

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

cbsasl/scram-sha/scram-sha.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,11 @@ void ScramShaBackend::addAttribute(std::ostream& out,
145145
break;
146146

147147
case 'r': // client nonce.. printable characters
148-
for (auto iter = value.begin(); iter != value.end(); ++iter) {
149-
if (*iter == ',' || !isprint(*iter)) {
148+
for (const auto& c : value) {
149+
if (c == ',' || !isprint(c)) {
150150
throw std::invalid_argument(
151-
"ScramShaBackend::addAttribute: "
152-
"Invalid character in client"
153-
" nonce");
151+
"ScramShaBackend::addAttribute: Invalid character in "
152+
"client nonce");
154153
}
155154
}
156155
out << value;
@@ -177,12 +176,11 @@ void ScramShaBackend::addAttribute(std::ostream& out,
177176
break;
178177

179178
case 'e':
180-
for (auto iter = value.begin(); iter != value.end(); ++iter) {
181-
if (*iter == ',' || !isprint(*iter)) {
179+
for (const auto& c : value) {
180+
if (c == ',' || !isprint(c)) {
182181
throw std::invalid_argument(
183-
"ScramShaBackend::addAttribute: "
184-
"Invalid character in error"
185-
" message");
182+
"ScramShaBackend::addAttribute: Invalid character in "
183+
"error message");
186184
}
187185
}
188186
out << value;
@@ -276,7 +274,7 @@ std::string ScramShaBackend::getClientProof() {
276274
proof.resize(clientKey.size());
277275

278276
auto total = proof.size();
279-
for (unsigned int ii = 0; ii < total; ++ii) {
277+
for (std::size_t ii = 0; ii < total; ++ii) {
280278
proof[ii] = ck[ii] ^ cs[ii];
281279
}
282280

@@ -293,7 +291,7 @@ ServerBackend::ServerBackend(server::ServerContext& ctx,
293291
/* Generate a challenge */
294292
cb::RandomGenerator randomGenerator;
295293

296-
std::array<char, 8> nonce;
294+
std::array<char, 8> nonce{};
297295
if (!randomGenerator.getBytes(nonce.data(), nonce.size())) {
298296
logging::log(&context,
299297
logging::Level::Error,
@@ -499,7 +497,7 @@ ClientBackend::ClientBackend(client::GetUsernameCallback& user_cb,
499497
ScramShaBackend(mechanism, algo) {
500498
cb::RandomGenerator randomGenerator;
501499

502-
std::array<char, 8> nonce;
500+
std::array<char, 8> nonce{};
503501
if (!randomGenerator.getBytes(nonce.data(), nonce.size())) {
504502
logging::log(&context,
505503
logging::Level::Error,

cbsasl/scram-sha/scram-sha.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class ScramShaBackend {
5858
* @param more set to true if we should add a trailing comma (more data
5959
* follows)
6060
*/
61-
void addAttribute(std::ostream& out,
62-
char key,
63-
const std::string& value,
64-
bool more);
61+
static void addAttribute(std::ostream& out,
62+
char key,
63+
const std::string& value,
64+
bool more);
6565

6666
/**
6767
* Add a property to the message list according to
@@ -77,7 +77,7 @@ class ScramShaBackend {
7777
* @param more set to true if we should add a trailing comma (more data
7878
* follows)
7979
*/
80-
void addAttribute(std::ostream& out, char key, int value, bool more);
80+
static void addAttribute(std::ostream& out, char key, int value, bool more);
8181

8282
std::string getServerSignature();
8383

0 commit comments

Comments
 (0)