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

Side by Side Diff: net/tools/domain_security_preload_generator/spki_hash.cc

Issue 2551153003: Add static domain security state generator tool. (Closed)
Patch Set: Fix iOS? Created 4 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "net/tools/domain_security_preload_generator/spki_hash.h"
6
7 #include <string>
8
9 #include "base/base64.h"
10 #include "base/logging.h"
11 #include "base/strings/string_util.h"
12 #include "third_party/boringssl/src/include/openssl/sha.h"
13
14 namespace net {
15
16 namespace transport_security_state {
17
18 SPKIHash::SPKIHash() {}
19
20 SPKIHash::~SPKIHash() {}
21
22 bool SPKIHash::FromString(const std::string& hash_string) {
23 std::string base64_string;
24
25 if (!base::StartsWith(hash_string, "sha256/",
26 base::CompareCase::INSENSITIVE_ASCII)) {
27 return false;
28 }
29 base64_string = hash_string.substr(7);
30
31 std::string decoded;
32 if (!base::Base64Decode(base64_string, &decoded)) {
33 return false;
34 }
35
36 if (decoded.size() != size()) {
37 return false;
38 }
39
40 memcpy(data_, decoded.data(), decoded.size());
41 return true;
42 }
43
44 void SPKIHash::CalculateFromBytes(const uint8_t* input, size_t input_length) {
45 SHA256(input, input_length, data_);
46 }
47
48 } // namespace transport_security_state
49
50 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698