OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "google_apis/gaia/oauth_request_signer.h" | 5 #include "google_apis/gaia/oauth_request_signer.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <cstdlib> | 9 #include <cstdlib> |
10 #include <cstring> | 10 #include <cstring> |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 | 197 |
198 // Creates the value for the oauth_signature parameter when the | 198 // Creates the value for the oauth_signature parameter when the |
199 // oauth_signature_method is HMAC-SHA1. | 199 // oauth_signature_method is HMAC-SHA1. |
200 bool SignHmacSha1(const std::string& text, | 200 bool SignHmacSha1(const std::string& text, |
201 const std::string& key, | 201 const std::string& key, |
202 std::string* signature_return) { | 202 std::string* signature_return) { |
203 crypto::HMAC hmac(crypto::HMAC::SHA1); | 203 crypto::HMAC hmac(crypto::HMAC::SHA1); |
204 DCHECK(hmac.DigestLength() == kHmacDigestLength); | 204 DCHECK(hmac.DigestLength() == kHmacDigestLength); |
205 unsigned char digest[kHmacDigestLength]; | 205 unsigned char digest[kHmacDigestLength]; |
206 bool result = hmac.Init(key) && | 206 bool result = hmac.Init(key) && |
207 hmac.Sign(text, digest, kHmacDigestLength) && | 207 hmac.Sign(text, digest, kHmacDigestLength); |
208 base::Base64Encode(std::string(reinterpret_cast<const char*>(digest), | 208 if (result) |
brettw
2013/12/09 19:36:26
Use {} for this since it's >1 line.
| |
209 kHmacDigestLength), | 209 base::Base64Encode( |
210 signature_return); | 210 std::string(reinterpret_cast<const char*>(digest), kHmacDigestLength), |
211 signature_return); | |
211 return result; | 212 return result; |
212 } | 213 } |
213 | 214 |
214 // Creates the value for the oauth_signature parameter when the | 215 // Creates the value for the oauth_signature parameter when the |
215 // oauth_signature_method is PLAINTEXT. | 216 // oauth_signature_method is PLAINTEXT. |
216 // | 217 // |
217 // Not yet implemented, and might never be. | 218 // Not yet implemented, and might never be. |
218 bool SignPlaintext(const std::string& text, | 219 bool SignPlaintext(const std::string& text, |
219 const std::string& key, | 220 const std::string& key, |
220 std::string* result) { | 221 std::string* result) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 signed_text += | 449 signed_text += |
449 base::StringPrintf( | 450 base::StringPrintf( |
450 "%s=\"%s\"", | 451 "%s=\"%s\"", |
451 OAuthRequestSigner::Encode(param->first).c_str(), | 452 OAuthRequestSigner::Encode(param->first).c_str(), |
452 OAuthRequestSigner::Encode(param->second).c_str()); | 453 OAuthRequestSigner::Encode(param->second).c_str()); |
453 } | 454 } |
454 *signed_text_return = signed_text; | 455 *signed_text_return = signed_text; |
455 } | 456 } |
456 return is_signed; | 457 return is_signed; |
457 } | 458 } |
OLD | NEW |