Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: net/http/http_mac_signature.cc

Issue 7522014: Add WARN_UNUSED_RESULT to crypto/hmac.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase onto CL 7532020 and update remoting Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_mac_signature.h ('k') | net/http/http_mac_signature_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_mac_signature.cc
diff --git a/net/http/http_mac_signature.cc b/net/http/http_mac_signature.cc
index 32f1e0cd4c5dc20a7eda0e3d6898d4a4144b6bc2..1e3ea95d2fd83297ec9e861304b433f4819a0e43 100644
--- a/net/http/http_mac_signature.cc
+++ b/net/http/http_mac_signature.cc
@@ -95,28 +95,38 @@ bool HttpMacSignature::AddHttpInfo(const std::string& method,
return true;
}
-std::string HttpMacSignature::GenerateAuthorizationHeader() {
- DCHECK(!id_.empty()) << "Call AddStateInfo first.";
- DCHECK(!method_.empty()) << "Call AddHttpInfo first.";
+bool HttpMacSignature::GenerateAuthorizationHeader(std::string* header) {
+ if (id_.empty()) {
+ NOTREACHED() << "Call AddStateInfo first.";
+ return false;
+ }
+ if (method_.empty()) {
+ NOTREACHED() << "Call AddHttpInfo first.";
+ return false;
+ }
std::string age = base::Int64ToString(
(base::Time::Now() - creation_date_).InSeconds());
std::string nonce = GenerateNonce();
- return GenerateHeaderString(age, nonce);
+ return GenerateHeaderString(age, nonce, header);
}
-std::string HttpMacSignature::GenerateHeaderString(const std::string& age,
- const std::string& nonce) {
- std::string mac = GenerateMAC(age, nonce);
+bool HttpMacSignature::GenerateHeaderString(const std::string& age,
+ const std::string& nonce,
+ std::string* header) {
+ std::string mac;
+ if (!GenerateMAC(age, nonce, &mac))
+ return false;
DCHECK(IsPlainString(age));
DCHECK(IsPlainString(nonce));
DCHECK(IsPlainString(mac));
- return "MAC id=\"" + id_ +
+ *header = "MAC id=\"" + id_ +
"\", nonce=\"" + age + ":" + nonce +
"\", mac=\"" + mac + "\"";
+ return true;
}
std::string HttpMacSignature::GenerateNormalizedRequest(
@@ -135,25 +145,34 @@ std::string HttpMacSignature::GenerateNormalizedRequest(
return normalized_request;
}
-std::string HttpMacSignature::GenerateMAC(const std::string& age,
- const std::string& nonce) {
+bool HttpMacSignature::GenerateMAC(const std::string& age,
+ const std::string& nonce,
+ std::string* mac) {
std::string request = GenerateNormalizedRequest(age, nonce);
crypto::HMAC hmac(mac_algorithm_);
- hmac.Init(mac_key_);
+ if (!hmac.Init(mac_key_)) {
+ NOTREACHED();
+ return false;
+ }
std::string signature;
size_t length = hmac.DigestLength();
char* buffer = WriteInto(&signature, length);
- bool result = hmac.Sign(request,
- reinterpret_cast<unsigned char*>(buffer),
- length);
- DCHECK(result);
+ if (!hmac.Sign(request, reinterpret_cast<unsigned char*>(buffer),
+ length)) {
+ NOTREACHED();
+ return false;
+ }
std::string encoded_signature;
- result = base::Base64Encode(signature, &encoded_signature);
- DCHECK(result);
- return encoded_signature;
+ if (!base::Base64Encode(signature, &encoded_signature)) {
+ NOTREACHED();
+ return false;
+ }
+
+ mac->swap(encoded_signature);
+ return true;
}
} // namespace net
« no previous file with comments | « net/http/http_mac_signature.h ('k') | net/http/http_mac_signature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698