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

Side by Side Diff: chrome/browser/autofill/wallet/full_wallet.cc

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and most fixes from Albert's initial review. Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autofill/wallet/full_wallet.h"
6
7 #include "base/logging.h"
8 #include "base/string_number_conversions.h"
9 #include "base/values.h"
10
Dan Beam 2012/11/30 19:55:52 nit: remove double \n
ahutter 2012/12/01 04:06:51 Done.
11
12 namespace {
13
14 size_t kPanSize = 16;
15 size_t kBinSize = 6;
16 size_t kCvnSize = 3;
17
18 } // end anonymous namespace
19
20 namespace wallet {
21
22 FullWallet::FullWallet(int expiration_month,
23 int expiration_year,
24 const std::string& iin,
25 const std::string& encrypted_rest,
26 Address* billing_address,
27 Address* shipping_address,
28 std::vector<std::string> required_actions)
29 : expiration_month_(expiration_month),
30 expiration_year_(expiration_year),
31 iin_(iin),
32 encrypted_rest_(encrypted_rest),
33 billing_address_(billing_address),
34 shipping_address_(shipping_address),
35 required_actions_(required_actions) {}
Dan Beam 2012/11/30 19:55:52 do you need to DCHECK() any of these pointers?
ahutter 2012/12/01 04:06:51 Except for testing, this constructor should only b
36
37 FullWallet::~FullWallet() {
38 }
39
40 FullWallet* FullWallet::CreateFullWallet(DictionaryValue* dictionary) {
Dan Beam 2012/11/30 19:55:52 nit: why isn't this also a scoped_ptr<FullWallet>
ahutter 2012/12/01 04:06:51 Header file comment specifies that the caller owns
Dan Beam 2012/12/05 19:34:59 I guess if it's called Create*() that's implied en
41 DCHECK(dictionary);
42 ListValue* required_actions_list;
43 std::vector<std::string> required_actions;
44 if (dictionary->GetList("required_action", &required_actions_list)) {
45 for (size_t i = 0; i < required_actions_list->GetSize(); i++) {
46 std::string action;
47 if (required_actions_list->GetString(i, &action))
48 required_actions.push_back(action);
49 }
50 if (required_actions.size() > 0) {
51 return new FullWallet(-1, -1, "", "", NULL, NULL, required_actions);
52 }
53 } else {
54 VLOG(1) << "Response from Google wallet missing required actions";
Dan Beam 2012/11/30 19:55:52 nit: DVLOG unless you want this to compile into re
ahutter 2012/12/01 04:06:51 Done.
55 }
56
57 int expiration_month;
58 if (!dictionary->GetInteger("expiration_month", &expiration_month)) {
59 DLOG(ERROR) << "Response from Google wallet missing expiration month";
60 return NULL;
61 }
Dan Beam 2012/11/30 19:55:52 nit: \n after each if() IMO
ahutter 2012/12/01 04:06:51 Done.
62 int expiration_year;
63 if (!dictionary->GetInteger("expiration_year", &expiration_year)) {
64 DLOG(ERROR) << "Response from Google wallet missing expiration year";
65 return NULL;
66 }
67 std::string iin;
68 if (!dictionary->GetString("iin", &iin)) {
69 DLOG(ERROR) << "Response from Google wallet missing iin";
70 return NULL;
71 }
72 std::string encrypted_rest;
73 if (!dictionary->GetString("rest", &encrypted_rest)) {
74 DLOG(ERROR) << "Response from Google wallet missing rest";
75 return NULL;
76 }
77 DictionaryValue* billing_address_dict;
78 if (!dictionary->GetDictionary("billing_address", &billing_address_dict)) {
79 DLOG(ERROR) << "Response from Google wallet missing billing address";
80 return NULL;
81 }
82 Address* billing_address =
83 Address::CreateIdedAddress(billing_address_dict);
84 if (!billing_address) {
85 DLOG(ERROR) << "Response from Google wallet has malformed billing address";
86 return NULL;
87 }
88
89 DictionaryValue* shipping_address_dict;
90 Address* shipping_address;
91 if (dictionary->GetDictionary("shipping_address", &shipping_address_dict)) {
92 shipping_address =
93 Address::CreateIdedAddress(shipping_address_dict);
94 } else {
95 VLOG(1) << "Response from Google wallet missing shipping address";
96 }
97
98 return new FullWallet(expiration_month,
99 expiration_year,
100 iin,
101 encrypted_rest,
102 billing_address,
103 shipping_address,
104 required_actions);
105 }
106
107 bool FullWallet::operator==(const FullWallet& other) const {
108 if (expiration_month_ != other.expiration_month_)
109 return false;
110 if (expiration_year_ != other.expiration_year_)
111 return false;
112 if (iin_.compare(other.iin_) != 0)
113 return false;
114 if (encrypted_rest_.compare(other.encrypted_rest_) != 0)
115 return false;
116 if (billing_address_.get() && other.billing_address_.get()) {
117 if (*billing_address_.get() != *other.billing_address_.get())
118 return false;
119 } else if (billing_address_.get() || other.billing_address_.get()) {
120 return false;
121 }
122 if (shipping_address_.get() && other.shipping_address_.get()) {
123 if (*shipping_address_.get() != *other.shipping_address_.get())
124 return false;
125 } else if (shipping_address_.get() || other.shipping_address_.get()) {
126 return false;
127 }
128 if (required_actions_ != other.required_actions_)
129 return false;
130 return true;
131 }
132
133 bool FullWallet::operator!=(const FullWallet& other) const {
134 return !(*this == other);
135 }
136
137 const std::string FullWallet::GetPAN(void* otp, size_t length) {
Dan Beam 2012/11/30 19:55:52 nit: generally abbreviations that are 3 or more le
ahutter 2012/12/01 04:06:51 Done.
138 if (cvn_.empty())
139 DecryptCardInfo((uint8*) otp, length);
140 return pan_;
141 }
142
143 const std::string FullWallet::GetCVN(void* otp, size_t length) {
144 if (pan_.empty())
145 DecryptCardInfo((uint8*) otp, length);
146 return cvn_;
147 }
148
149 void FullWallet::DecryptCardInfo(uint8* otp, size_t length) {
Dan Beam 2012/11/30 19:55:52 if you'd like to add comments to any of these step
ahutter 2012/12/01 04:06:51 Done.
150 std::vector<uint8> operating_data;
151 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) {
152 DLOG(ERROR) << "Failed to parse rest";
153 return;
154 }
155 DCHECK_EQ(length, operating_data.size());
156 uint8* result = new uint8[length];
Dan Beam 2012/11/30 19:55:52 I'm a bit of a C++ n00b, but why can't you simply
ahutter 2012/12/01 04:06:51 The linter doesn't like arrays the aren't sized by
157 for (size_t i = 0; i < length; i++)
158 result[i] = otp[i] ^ operating_data[i];
159 std::string hex_decrypted = base::HexEncode(result, length);
160 delete[] result;
161 int64 decrypted;
162 if (!base::HexStringToInt64(hex_decrypted, &decrypted)) {
163 DLOG(ERROR) << "Failed to parse decrypted";
Dan Beam 2012/11/30 19:55:52 decrypted? maybe decrypted needs a better? sentenc
ahutter 2012/12/01 04:06:51 Done.
164 return;
165 }
166 std::string card_info = base::Int64ToString(decrypted);
Dan Beam 2012/11/30 19:55:52 nit: are we in a \n famine? :P
ahutter 2012/12/01 04:06:51 Done.
167
168 size_t padded_length = (kPanSize - kBinSize + kCvnSize);
Dan Beam 2012/11/30 19:55:52 nit: these () aren't necessary, and the C++ style
ahutter 2012/12/01 04:06:51 Done.
169 if (card_info.size() != padded_length)
170 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0');
171
172 size_t split = kPanSize - kBinSize;
173 cvn_ = card_info.substr(split);
174 pan_ = iin_ + card_info.substr(0, split);
175 }
176
177 } // end wallet namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698