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

Side by Side Diff: base/sha1_win.cc

Issue 7972024: Update SHA1_LENGTH -> kSHA1Length to match previous change to SHA256_LENGTH. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
« no previous file with comments | « base/sha1_unittest.cc ('k') | chrome/app/client_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/sha1.h" 5 #include "base/sha1.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <wincrypt.h> 8 #include <wincrypt.h>
9 9
10 // This file is not being compiled at the moment (see bug 47218). If we keep 10 // This file is not being compiled at the moment (see bug 47218). If we keep
11 // sha1 inside base, we cannot depend on src/crypto. 11 // sha1 inside base, we cannot depend on src/crypto.
12 // #include "crypto/scoped_capi_types.h" 12 // #include "crypto/scoped_capi_types.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 std::string SHA1HashString(const std::string& str) { 17 std::string SHA1HashString(const std::string& str) {
18 ScopedHCRYPTPROV provider; 18 ScopedHCRYPTPROV provider;
19 if (!CryptAcquireContext(provider.receive(), NULL, NULL, PROV_RSA_FULL, 19 if (!CryptAcquireContext(provider.receive(), NULL, NULL, PROV_RSA_FULL,
20 CRYPT_VERIFYCONTEXT)) { 20 CRYPT_VERIFYCONTEXT)) {
21 LOG(ERROR) << "CryptAcquireContext failed: " << GetLastError(); 21 LOG(ERROR) << "CryptAcquireContext failed: " << GetLastError();
22 return std::string(SHA1_LENGTH, '\0'); 22 return std::string(kSHA1Length, '\0');
23 } 23 }
24 24
25 { 25 {
26 ScopedHCRYPTHASH hash; 26 ScopedHCRYPTHASH hash;
27 if (!CryptCreateHash(provider, CALG_SHA1, 0, 0, hash.receive())) { 27 if (!CryptCreateHash(provider, CALG_SHA1, 0, 0, hash.receive())) {
28 LOG(ERROR) << "CryptCreateHash failed: " << GetLastError(); 28 LOG(ERROR) << "CryptCreateHash failed: " << GetLastError();
29 return std::string(SHA1_LENGTH, '\0'); 29 return std::string(kSHA1Length, '\0');
30 } 30 }
31 31
32 if (!CryptHashData(hash, reinterpret_cast<CONST BYTE*>(str.data()), 32 if (!CryptHashData(hash, reinterpret_cast<CONST BYTE*>(str.data()),
33 static_cast<DWORD>(str.length()), 0)) { 33 static_cast<DWORD>(str.length()), 0)) {
34 LOG(ERROR) << "CryptHashData failed: " << GetLastError(); 34 LOG(ERROR) << "CryptHashData failed: " << GetLastError();
35 return std::string(SHA1_LENGTH, '\0'); 35 return std::string(kSHA1Length, '\0');
36 } 36 }
37 37
38 DWORD hash_len = 0; 38 DWORD hash_len = 0;
39 DWORD buffer_size = sizeof hash_len; 39 DWORD buffer_size = sizeof hash_len;
40 if (!CryptGetHashParam(hash, HP_HASHSIZE, 40 if (!CryptGetHashParam(hash, HP_HASHSIZE,
41 reinterpret_cast<unsigned char*>(&hash_len), 41 reinterpret_cast<unsigned char*>(&hash_len),
42 &buffer_size, 0)) { 42 &buffer_size, 0)) {
43 LOG(ERROR) << "CryptGetHashParam(HP_HASHSIZE) failed: " << GetLastError(); 43 LOG(ERROR) << "CryptGetHashParam(HP_HASHSIZE) failed: " << GetLastError();
44 return std::string(SHA1_LENGTH, '\0'); 44 return std::string(kSHA1Length, '\0');
45 } 45 }
46 46
47 std::string result; 47 std::string result;
48 if (!CryptGetHashParam(hash, HP_HASHVAL, 48 if (!CryptGetHashParam(hash, HP_HASHVAL,
49 // We need the + 1 here not because the call will write a trailing \0, 49 // We need the + 1 here not because the call will write a trailing \0,
50 // but so that result.length() is correctly set to |hash_len|. 50 // but so that result.length() is correctly set to |hash_len|.
51 reinterpret_cast<BYTE*>(WriteInto(&result, hash_len + 1)), &hash_len, 51 reinterpret_cast<BYTE*>(WriteInto(&result, hash_len + 1)), &hash_len,
52 0))) { 52 0))) {
53 LOG(ERROR) << "CryptGetHashParam(HP_HASHVAL) failed: " << GetLastError(); 53 LOG(ERROR) << "CryptGetHashParam(HP_HASHVAL) failed: " << GetLastError();
54 return std::string(SHA1_LENGTH, '\0'); 54 return std::string(kSHA1Length, '\0');
55 } 55 }
56 56
57 if (hash_len != SHA1_LENGTH) { 57 if (hash_len != kSHA1Length) {
58 LOG(ERROR) << "Returned hash value is wrong length: " << hash_len 58 LOG(ERROR) << "Returned hash value is wrong length: " << hash_len
59 << " should be " << SHA1_LENGTH; 59 << " should be " << kSHA1Length;
60 return std::string(SHA1_LENGTH, '\0'); 60 return std::string(kSHA1Length, '\0');
61 } 61 }
62 62
63 return result; 63 return result;
64 } 64 }
65 } 65 }
66 66
67 } // namespace base 67 } // namespace base
OLDNEW
« no previous file with comments | « base/sha1_unittest.cc ('k') | chrome/app/client_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698