| Index: components/payments/content/android/utility/fingerprint_parser.cc
|
| diff --git a/components/payments/content/android/utility/fingerprint_parser.cc b/components/payments/content/android/utility/fingerprint_parser.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1dff204e622c1b44c90bf4380e9b3186d1e74173
|
| --- /dev/null
|
| +++ b/components/payments/content/android/utility/fingerprint_parser.cc
|
| @@ -0,0 +1,50 @@
|
| +// Copyright 2017 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 "components/payments/content/android/utility/fingerprint_parser.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/numerics/safe_conversions.h"
|
| +
|
| +namespace payments {
|
| +namespace {
|
| +
|
| +bool IsUpperCaseHexDigit(char c) {
|
| + return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F');
|
| +}
|
| +
|
| +uint8_t HexDigitToByte(char c) {
|
| + DCHECK(IsUpperCaseHexDigit(c));
|
| + return base::checked_cast<uint8_t>(c >= '0' && c <= '9' ? c - '0'
|
| + : c - 'A' + 10);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +std::vector<uint8_t> FingerprintStringToByteArray(const std::string& input) {
|
| + std::vector<uint8_t> output;
|
| + if (input.size() != 32 * 3 - 1)
|
| + return output;
|
| +
|
| + for (size_t i = 0; i < input.size(); i += 3) {
|
| + if (i < input.size() - 2 && input[i + 2] != ':') {
|
| + output.clear();
|
| + return output;
|
| + }
|
| +
|
| + char big_end = input[i];
|
| + char little_end = input[i + 1];
|
| + if (!IsUpperCaseHexDigit(big_end) || !IsUpperCaseHexDigit(little_end)) {
|
| + output.clear();
|
| + return output;
|
| + }
|
| +
|
| + output.push_back(HexDigitToByte(big_end) * static_cast<uint8_t>(16) +
|
| + HexDigitToByte(little_end));
|
| + }
|
| +
|
| + return output;
|
| +}
|
| +
|
| +} // namespace payments
|
|
|