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

Side by Side Diff: net/http/http_mac_signature.cc

Issue 8418034: Make string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_mac_signature.h" 5 #include "net/http/http_mac_signature.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 std::string request = GenerateNormalizedRequest(age, nonce); 151 std::string request = GenerateNormalizedRequest(age, nonce);
152 152
153 crypto::HMAC hmac(mac_algorithm_); 153 crypto::HMAC hmac(mac_algorithm_);
154 if (!hmac.Init(mac_key_)) { 154 if (!hmac.Init(mac_key_)) {
155 NOTREACHED(); 155 NOTREACHED();
156 return false; 156 return false;
157 } 157 }
158 158
159 std::string signature; 159 std::string signature;
160 size_t length = hmac.DigestLength(); 160 size_t length = hmac.DigestLength();
161 char* buffer = WriteInto(&signature, length); 161 DCHECK_GT(length, 0u);
162 if (!hmac.Sign(request, reinterpret_cast<unsigned char*>(buffer), 162 if (!hmac.Sign(request,
163 length)) { 163 // We need the + 1 here not because the call will write a trailing \0,
164 // but so that signature.length() is correctly set to |length|.
165 reinterpret_cast<unsigned char*>(WriteInto(&signature, length + 1)),
166 length)) {
164 NOTREACHED(); 167 NOTREACHED();
165 return false; 168 return false;
166 } 169 }
167 170
168 std::string encoded_signature; 171 std::string encoded_signature;
169 if (!base::Base64Encode(signature, &encoded_signature)) { 172 if (!base::Base64Encode(signature, &encoded_signature)) {
170 NOTREACHED(); 173 NOTREACHED();
171 return false; 174 return false;
172 } 175 }
173 176
174 mac->swap(encoded_signature); 177 mac->swap(encoded_signature);
175 return true; 178 return true;
176 } 179 }
177 180
178 } // namespace net 181 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698