Index: chrome/browser/autofill/wallet/full_wallet.cc |
diff --git a/chrome/browser/autofill/wallet/full_wallet.cc b/chrome/browser/autofill/wallet/full_wallet.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bf7e7e0f93d842dab4016b2e0e8edd17f4b7a396 |
--- /dev/null |
+++ b/chrome/browser/autofill/wallet/full_wallet.cc |
@@ -0,0 +1,205 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/autofill/wallet/full_wallet.h" |
+ |
+#include "base/logging.h" |
+#include "base/string_number_conversions.h" |
+#include "base/values.h" |
+ |
+ |
+namespace { |
+ |
+size_t kPanSize = 16; |
+size_t kBinSize = 6; |
+size_t kCvnSize = 3; |
benquan
2012/12/15 02:48:59
Are these constants always true?
Some credit card
ahutter
2012/12/17 17:23:02
These are specific to our proxy cards.
|
+ |
+} // end anonymous namespace |
+ |
+namespace wallet { |
+ |
+FullWallet::FullWallet(int expiration_month, |
+ int expiration_year, |
+ const std::string& iin, |
+ const std::string& rest, |
Raman Kakilate
2012/11/17 02:28:31
should we call out that this value is otp-crypted
ahutter
2012/11/27 00:46:12
Done.
|
+ Address* billing_address, |
+ Address* shipping_address, |
+ std::vector<std::string> required_actions) |
benquan
2012/12/15 02:48:59
this should be const reference
ahutter
2012/12/17 17:23:02
It is in the most recent CL.
|
+ : expiration_month_(expiration_month), |
+ expiration_year_(expiration_year), |
+ iin_(iin), |
+ rest_(rest), |
+ billing_address_(billing_address), |
+ shipping_address_(shipping_address), |
+ required_actions_(required_actions) {} |
+ |
+FullWallet::~FullWallet() { |
+} |
+ |
+FullWallet* FullWallet::CreateFromDictionary(DictionaryValue* dictionary) { |
+ DCHECK(dictionary); |
+ ListValue* required_actions_list; |
+ std::vector<std::string> required_actions; |
+ if (dictionary->GetList("required_action", &required_actions_list)) { |
+ for (size_t i = 0; i < required_actions_list->GetSize(); i++) { |
+ std::string action; |
+ if (required_actions_list->GetString(i, &action)) |
+ required_actions.push_back(action); |
+ } |
+ if (required_actions.size() > 0) { |
+ return new FullWallet(-1, -1, "", "", NULL, NULL, required_actions); |
+ } |
+ } else { |
+ VLOG(1) << "Response from Google wallet missing required actions"; |
+ } |
+ |
+ int expiration_month; |
+ if (!dictionary->GetInteger("expiration_month", &expiration_month)) { |
+ LOG(ERROR) << "Response from Google wallet missing expiration month"; |
+ return NULL; |
+ } |
+ int expiration_year; |
+ if (!dictionary->GetInteger("expiration_year", &expiration_year)) { |
+ LOG(ERROR) << "Response from Google wallet missing expiration year"; |
+ return NULL; |
+ } |
+ std::string iin; |
+ if (!dictionary->GetString("iin", &iin)) { |
+ LOG(ERROR) << "Response from Google wallet missing iin"; |
+ return NULL; |
+ } |
+ std::string rest; |
+ if (!dictionary->GetString("rest", &rest)) { |
+ LOG(ERROR) << "Response from Google wallet missing rest"; |
+ return NULL; |
+ } |
+ DictionaryValue* billing_address_dict; |
+ if (!dictionary->GetDictionary("billing_address", &billing_address_dict)) { |
+ LOG(ERROR) << "Response from Google wallet missing billing address"; |
+ return NULL; |
+ } |
+ Address* billing_address = |
+ Address::CreateFromIdedDictionary(billing_address_dict); |
+ if (!billing_address) { |
+ LOG(ERROR) << "Response from Google wallet has malformed billing address"; |
+ return NULL; |
+ } |
+ |
+ DictionaryValue* shipping_address_dict; |
+ Address* shipping_address; |
+ if (dictionary->GetDictionary("shipping_address", &shipping_address_dict)) { |
+ shipping_address = |
+ Address::CreateFromIdedDictionary(shipping_address_dict); |
+ } else { |
+ VLOG(1) << "Response from Google wallet missing shipping address"; |
+ } |
+ |
+ return new FullWallet(expiration_month, |
+ expiration_year, |
+ iin, |
+ rest, |
+ billing_address, |
+ shipping_address, |
+ required_actions); |
+} |
+ |
+bool FullWallet::operator==(const FullWallet& other) const { |
+ if (expiration_month_ != other.expiration_month_) |
+ return false; |
+ if (expiration_year_ != other.expiration_year_) |
+ return false; |
+ if (iin_.compare(other.iin_) != 0) |
+ return false; |
+ if (rest_.compare(other.rest_) != 0) |
+ return false; |
+ if (billing_address_.get() && other.billing_address_.get()) { |
+ if (*billing_address_.get() != *other.billing_address_.get()) |
+ return false; |
+ } else if (billing_address_.get() || other.billing_address_.get()) { |
+ return false; |
+ } |
+ if (shipping_address_.get() && other.shipping_address_.get()) { |
+ if (*shipping_address_.get() != *other.shipping_address_.get()) |
+ return false; |
+ } else if (shipping_address_.get() || other.shipping_address_.get()) { |
+ return false; |
+ } |
+ if (required_actions_ != other.required_actions_) |
+ return false; |
+ return true; |
+} |
+ |
+bool FullWallet::operator!=(const FullWallet& other) const { |
+ return !(*this == other); |
+} |
+ |
+std::ostream& operator<<(std::ostream& o, |
+ const FullWallet& full_wallet) { |
+ o << "Expiration month : " << full_wallet.expiration_month_ << std::endl; |
+ o << "Expiration year : " << full_wallet.expiration_year_ << std::endl; |
+ o << "Iin : " << full_wallet.iin_ << std::endl; |
+ o << "Rest : " << full_wallet.rest_ << std::endl; |
+ o << "Billing address : " << full_wallet.billing_address_ << std::endl; |
+ o << "Shipping address : " << full_wallet.shipping_address_ << std::endl; |
+// o << "Required actions : " << full_wallet.required_actions_ << std::endl; |
+ return o; |
+} |
Raman Kakilate
2012/11/17 02:28:31
Do we need this in final code ?
ahutter
2012/11/27 00:46:12
Removing.
|
+ |
+const std::string FullWallet::GetPAN(void* otp, size_t length) const { |
+ std::vector<uint8> operating_data; |
+ if (!base::HexStringToBytes(rest_, &operating_data)) { |
+ LOG(ERROR) << "Failed to parse rest"; |
+ return ""; |
+ } |
+ CHECK_EQ(length, operating_data.size()); |
Raman Kakilate
2012/11/17 02:28:31
Do we have to crash chrome ?
ahutter
2012/11/27 00:46:12
Probably not.
|
+ char* result = new char[length]; |
+ char* otp_thing = (char*) otp; |
Raman Kakilate
2012/11/17 02:28:31
What not just char* in param ?
ahutter
2012/11/27 00:46:12
Done.
|
+ for (size_t i = 0; i < length; i++) |
+ result[i] = static_cast<uint8>(otp_thing[i]) ^ operating_data[i]; |
+ std::string hex_decrypted = base::HexEncode(result, length); |
+ delete[] result; |
+ int64 decrypted; |
+ if (!base::HexStringToInt64(hex_decrypted, &decrypted)) { |
+ LOG(ERROR) << "Failed to parse decrypted"; |
+ return ""; |
+ } |
Raman Kakilate
2012/11/17 02:28:31
Extract this block of code to a private method ?..
ahutter
2012/11/27 00:46:12
Done.
|
+ std::string card_info = base::Int64ToString(decrypted); |
+ |
+ size_t padded_length = (kPanSize - kBinSize + kCvnSize); |
+ if (card_info.size() != padded_length) |
+ card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
+ |
+ size_t split = kPanSize - kBinSize; |
+ return iin_ + card_info.substr(0, split); |
+} |
+ |
+const std::string FullWallet::GetCVN(void* otp, size_t length) const { |
+ std::vector<uint8> operating_data; |
+ if (!base::HexStringToBytes(rest_, &operating_data)) { |
+ LOG(ERROR) << "Failed to parse rest"; |
+ return ""; |
+ } |
+ CHECK_EQ(length, operating_data.size()); |
+ char* result = new char[length]; |
+ char* otp_thing = (char*) otp; |
+ for (size_t i = 0; i < length; i++) |
+ result[i] = static_cast<uint8>(otp_thing[i]) ^ operating_data[i]; |
+ std::string hex_decrypted = base::HexEncode(result, length); |
+ delete[] result; |
+ int64 decrypted; |
+ if (!base::HexStringToInt64(hex_decrypted, &decrypted)) { |
+ LOG(ERROR) << "Failed to parse decrypted"; |
+ return ""; |
+ } |
+ std::string card_info = base::Int64ToString(decrypted); |
+ |
+ size_t padded_length = (kPanSize - kBinSize + kCvnSize); |
+ if (card_info.size() != padded_length) |
+ card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
+ |
+ size_t split = kPanSize - kBinSize; |
Raman Kakilate
2012/11/17 02:28:31
Why do we do this in a getter ? GetPAN and GetCVN
ahutter
2012/11/27 00:46:12
I was being lazy. Fixed.
|
+ return card_info.substr(split); |
+} |
+ |
+} // end wallet namespace |