Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 #ifndef NET_CERT_CT_EV_WHITELIST_H_ | |
| 6 #define NET_CERT_CT_EV_WHITELIST_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "net/base/net_export.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 namespace ct { | |
| 17 | |
| 18 namespace internal { | |
| 19 | |
| 20 /** | |
|
wtc
2014/09/02 23:03:02
Unless you are using a tool like javadoc or doxyge
Eran Messeri
2014/09/03 09:38:50
Done.
| |
| 21 * Abstraction over a stream of bits, to be read independently | |
| 22 * of the bytes they're packed into. Bits are read MSB-first from the stream. | |
| 23 * It is limited to 64-bit reads and is inefficient as a design choice - Since | |
| 24 * it is used infrequently to unpack the Golomb-coded EV certificate hashes | |
| 25 * whitelist in a blocking thread. | |
| 26 * | |
| 27 * This class is declared here so it can be tested. | |
| 28 */ | |
| 29 class NET_EXPORT_PRIVATE BitStreamReader { | |
| 30 public: | |
| 31 BitStreamReader(const char* source, size_t length); | |
| 32 | |
| 33 // Reads unary-encoded number into |out|. Returns true if | |
| 34 // there was at least one bit to read, false otherwise. | |
| 35 bool ReadUnaryEncoding(uint64* out); | |
| 36 // Reads |num_bits| (up to 64) into |out|. |out| is filled from the MSB to the | |
| 37 // LSB. If |num_bits| is less than 64, the most significant |64 - num_bits| | |
| 38 // bits are left unused. Returns true if the stream had the requested | |
|
wtc
2014/09/02 23:03:02
Nit: "left unused" doesn't say what values those b
Eran Messeri
2014/09/03 09:38:51
Done.
| |
| 39 // |num_bits|, false otherwise. | |
| 40 bool ReadBits(uint8 num_bits, uint64* out); | |
| 41 // Returns the number of bits left in the stream. | |
| 42 uint64 BitsLeft() const; | |
| 43 | |
| 44 private: | |
| 45 // Reads a single bit. Within a byte, the bits are read from the MSB to the | |
| 46 // LSB. | |
| 47 uint8 ReadBit(); | |
| 48 | |
| 49 const char* const source_; | |
| 50 const size_t length_; | |
| 51 | |
| 52 // Index of the byte currently being read from. | |
| 53 uint64 current_byte_; | |
| 54 // Index of the last bit read within |current_byte_|. Since bits are read | |
| 55 // from the MSB to the LSB, this value is initialized to 7 and decreases | |
|
wtc
2014/09/02 23:03:02
Nit: decreases => decremented
Eran Messeri
2014/09/03 09:38:50
Done.
| |
| 56 // after each read. | |
| 57 int8 current_bit_; | |
| 58 }; | |
| 59 | |
| 60 // Given a Golomb-coded list of hashes in |compressed_whitelist|, unpack into | |
| 61 // |uncompressed_list|. Returns true if the format of the compressed whitelist | |
| 62 // is valid, false otherwise. | |
| 63 NET_EXPORT_PRIVATE bool UncompressEVWhitelist( | |
| 64 const std::string& compressed_whitelist, | |
| 65 std::set<std::string>* uncompressed_list); | |
| 66 | |
| 67 // Sets the given |ev_whitelist| into the global context. | |
| 68 // Note that |ev_whitelist| will contain the old EV whitelist data after this | |
| 69 // call as the implementation is using set::swap() to efficiently switch the | |
| 70 // sets. | |
| 71 NET_EXPORT_PRIVATE void SetEVWhitelistData(std::set<std::string>& ev_whitelist); | |
|
wtc
2014/09/02 23:03:02
IMPORTANT: a non-const reference is usually disall
Eran Messeri
2014/09/03 09:38:50
Acknowledged - Since this code is not performance-
| |
| 72 } // namespace internal | |
|
wtc
2014/09/02 23:03:02
Please add a blank line before this line.
Eran Messeri
2014/09/03 09:38:50
Done.
| |
| 73 | |
| 74 // Sets the global EV certificate hashes whitelist from | |
| 75 // |compressed_whitelist_file| in the global context, after uncompressing it. | |
| 76 // If the data in |compressed_whitelist_file| is not a valid compressed | |
| 77 // whitelist, does nothing. | |
| 78 NET_EXPORT void SetEVWhitelistFromFile( | |
| 79 const base::FilePath& compressed_whitelist_file); | |
| 80 | |
| 81 // Returns true if the |certificate_hash| appears in the EV certificate hashes | |
| 82 // whitelist. | |
| 83 NET_EXPORT bool IsCertificateHashInWhitelist( | |
| 84 const std::string& certificate_hash); | |
| 85 | |
| 86 } // namespace ct | |
| 87 | |
| 88 } // namespace net | |
| 89 | |
| 90 #endif // NET_CERT_CT_EV_WHITELIST_H_ | |
| OLD | NEW |