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

Side by Side Diff: crypto/hmac_mac.cc

Issue 7522014: Add WARN_UNUSED_RESULT to crypto/hmac.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win fix Created 9 years, 4 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 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 "crypto/hmac.h" 5 #include "crypto/hmac.h"
6 6
7 #include <CommonCrypto/CommonHMAC.h> 7 #include <CommonCrypto/CommonHMAC.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 24 matching lines...) Expand all
35 HMAC::~HMAC() { 35 HMAC::~HMAC() {
36 // Zero out key copy. 36 // Zero out key copy.
37 plat_->key_.assign(plat_->key_.length(), std::string::value_type()); 37 plat_->key_.assign(plat_->key_.length(), std::string::value_type());
38 plat_->key_.clear(); 38 plat_->key_.clear();
39 plat_->key_.reserve(0); 39 plat_->key_.reserve(0);
40 } 40 }
41 41
42 bool HMAC::Sign(const base::StringPiece& data, 42 bool HMAC::Sign(const base::StringPiece& data,
43 unsigned char* digest, 43 unsigned char* digest,
44 int digest_length) const { 44 int digest_length) const {
45 if (plat_->key_.empty()) {
46 // Init has not been called or has failed.
47 NOTREACHED();
48 return false;
49 }
50
45 CCHmacAlgorithm algorithm; 51 CCHmacAlgorithm algorithm;
46 int algorithm_digest_length; 52 int algorithm_digest_length;
47 switch (hash_alg_) { 53 switch (hash_alg_) {
48 case SHA1: 54 case SHA1:
49 algorithm = kCCHmacAlgSHA1; 55 algorithm = kCCHmacAlgSHA1;
50 algorithm_digest_length = CC_SHA1_DIGEST_LENGTH; 56 algorithm_digest_length = CC_SHA1_DIGEST_LENGTH;
51 break; 57 break;
52 case SHA256: 58 case SHA256:
53 algorithm = kCCHmacAlgSHA256; 59 algorithm = kCCHmacAlgSHA256;
54 algorithm_digest_length = CC_SHA256_DIGEST_LENGTH; 60 algorithm_digest_length = CC_SHA256_DIGEST_LENGTH;
55 break; 61 break;
56 default: 62 default:
57 NOTREACHED(); 63 NOTREACHED();
58 return false; 64 return false;
59 } 65 }
60 66
61 if (digest_length < algorithm_digest_length) { 67 if (digest_length < algorithm_digest_length) {
62 NOTREACHED(); 68 NOTREACHED();
63 return false; 69 return false;
64 } 70 }
65 71
66 CCHmac(algorithm, 72 CCHmac(algorithm,
67 plat_->key_.data(), plat_->key_.length(), data.data(), data.length(), 73 plat_->key_.data(), plat_->key_.length(), data.data(), data.length(),
68 digest); 74 digest);
69 75
70 return true; 76 return true;
71 } 77 }
72 78
73 } // namespace crypto 79 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/hmac.h ('k') | net/http/http_mac_signature.h » ('j') | net/http/http_mac_signature.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698