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

Side by Side Diff: components/autofill/core/browser/crypto/rc4_decryptor.h

Issue 1859453002: components/autofill: scoped_ptr -> unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 4 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_CRYPTO_RC4_DECRYPTOR_H_ 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_CRYPTO_RC4_DECRYPTOR_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_CRYPTO_RC4_DECRYPTOR_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_CRYPTO_RC4_DECRYPTOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include <memory>
11 #include <string> 12 #include <string>
12 #include "base/memory/scoped_ptr.h"
13 13
14 namespace autofill { 14 namespace autofill {
15 15
16 // This is modified RC4 decryption used for import of Toolbar autofill data 16 // This is modified RC4 decryption used for import of Toolbar autofill data
17 // only. The difference from the Crypto Api implementation is twofold: 17 // only. The difference from the Crypto Api implementation is twofold:
18 // First, it uses a non-standard key size (160 bit), not supported by Microsoft 18 // First, it uses a non-standard key size (160 bit), not supported by Microsoft
19 // (it supports only 40 and 128 bit for RC4). Second, it codes 128 words with 19 // (it supports only 40 and 128 bit for RC4). Second, it codes 128 words with
20 // value 0x0020 at the beginning of the code to enhance security. 20 // value 0x0020 at the beginning of the code to enhance security.
21 // 21 //
22 // This class used in 22 // This class used in
23 // components/autofill/core/browser/autofill_ie_toolbar_import_win.cc. 23 // components/autofill/core/browser/autofill_ie_toolbar_import_win.cc.
24 // 24 //
25 // This class should not be used anywhere else!!! 25 // This class should not be used anywhere else!!!
26 class RC4Decryptor { 26 class RC4Decryptor {
27 public: 27 public:
28 explicit RC4Decryptor(wchar_t const* password) { 28 explicit RC4Decryptor(wchar_t const* password) {
29 PrepareKey(reinterpret_cast<const uint8_t*>(password), 29 PrepareKey(reinterpret_cast<const uint8_t*>(password),
30 wcslen(password) * sizeof(wchar_t)); 30 wcslen(password) * sizeof(wchar_t));
31 std::wstring data; 31 std::wstring data;
32 // First 128 bytes should be spaces. 32 // First 128 bytes should be spaces.
33 data.resize(128, L' '); 33 data.resize(128, L' ');
34 Run(data.c_str()); 34 Run(data.c_str());
35 } 35 }
36 36
37 // Run the algorithm 37 // Run the algorithm
38 std::wstring Run(const std::wstring& data) { 38 std::wstring Run(const std::wstring& data) {
39 int data_size = data.length() * sizeof(wchar_t); 39 int data_size = data.length() * sizeof(wchar_t);
40 40
41 scoped_ptr<wchar_t[]> buffer(new wchar_t[data.length() + 1]); 41 std::unique_ptr<wchar_t[]> buffer(new wchar_t[data.length() + 1]);
42 memset(buffer.get(), 0, (data.length() + 1) * sizeof(wchar_t)); 42 memset(buffer.get(), 0, (data.length() + 1) * sizeof(wchar_t));
43 memcpy(buffer.get(), data.c_str(), data_size); 43 memcpy(buffer.get(), data.c_str(), data_size);
44 44
45 RunInternal(reinterpret_cast<uint8_t*>(buffer.get()), data_size); 45 RunInternal(reinterpret_cast<uint8_t*>(buffer.get()), data_size);
46 46
47 std::wstring result(buffer.get()); 47 std::wstring result(buffer.get());
48 48
49 // Clear the memory 49 // Clear the memory
50 memset(buffer.get(), 0, data_size); 50 memset(buffer.get(), 0, data_size);
51 return result; 51 return result;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 key_.x = x; 103 key_.x = x;
104 key_.y = y; 104 key_.y = y;
105 } 105 }
106 106
107 Rc4Key key_; 107 Rc4Key key_;
108 }; 108 };
109 109
110 } // namespace autofill 110 } // namespace autofill
111 111
112 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_CRYPTO_RC4_DECRYPTOR_H_ 112 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_CRYPTO_RC4_DECRYPTOR_H_
OLDNEW
« no previous file with comments | « components/autofill/core/browser/credit_card_field_unittest.cc ('k') | components/autofill/core/browser/email_field.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698