| OLD | NEW |
| (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 | |
| OLD | NEW |