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

Side by Side Diff: components/payments/content/android/utility/fingerprint_parser.cc

Issue 2645813006: Download web payment manifests. (Closed)
Patch Set: Rebase Created 3 years, 9 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
(Empty)
1 // Copyright 2017 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 "components/payments/content/android/utility/fingerprint_parser.h"
6
7 #include "base/logging.h"
8 #include "base/numerics/safe_conversions.h"
9
10 namespace payments {
11 namespace {
12
13 bool IsUpperCaseHexDigit(char c) {
14 return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F');
15 }
16
17 uint8_t HexDigitToByte(char c) {
18 DCHECK(IsUpperCaseHexDigit(c));
19 return base::checked_cast<uint8_t>(c >= '0' && c <= '9' ? c - '0'
20 : c - 'A' + 10);
21 }
22
23 } // namespace
24
25 std::vector<uint8_t> FingerprintStringToByteArray(const std::string& input) {
26 std::vector<uint8_t> output;
27 if (input.size() != 32 * 3 - 1)
28 return output;
29
30 for (size_t i = 0; i < input.size(); i += 3) {
31 if (i < input.size() - 2 && input[i + 2] != ':') {
32 output.clear();
33 return output;
34 }
35
36 char big_end = input[i];
37 char little_end = input[i + 1];
38 if (!IsUpperCaseHexDigit(big_end) || !IsUpperCaseHexDigit(little_end)) {
39 output.clear();
40 return output;
41 }
42
43 output.push_back(HexDigitToByte(big_end) * static_cast<uint8_t>(16) +
44 HexDigitToByte(little_end));
45 }
46
47 return output;
48 }
49
50 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698