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 /** | |
21 * Abstraction over a stream of bits, to be read independently | |
22 * of the bytes they're packed into. It is limited to 64-bit reads | |
23 * and is inefficient as a design choice - Since it is used infrequently | |
24 * to unpack the Golomb-coded EV certificate hashes whitelist in a | |
25 * 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|. Returns true if | |
37 // the stream had the requested |num_bits|, false otherwise. | |
38 bool ReadBits(uint8 num_bits, uint64* out); | |
wtc
2014/08/20 02:52:07
Please documents in which direction you are fillin
Eran Messeri
2014/09/02 12:20:23
Good points, done. Also added a class-level commen
| |
39 // Returns the number of bits left in the stream. | |
40 uint64 BitsLeft() const; | |
41 | |
42 private: | |
43 // Returns true if there are more bits to read in the stream. | |
44 bool HasMoreBits() const; | |
45 // Reads a single bit. | |
wtc
2014/08/20 02:52:07
Please document that within a byte, the bits are r
Eran Messeri
2014/09/02 12:20:23
Done.
| |
46 uint8 ReadBit(); | |
47 | |
48 const char* const source_; | |
49 const size_t length_; | |
50 | |
51 uint64 curr_byte_; | |
52 int8 curr_bit_; | |
wtc
2014/08/20 02:52:07
Nit: it would be nice to document these two member
Eran Messeri
2014/09/02 12:20:23
Very valid point, code reviews should not be puzzl
| |
53 }; | |
54 | |
55 // Given a Golomb-coded list of hashes in |compressed_whitelist|, unpack into | |
56 // |uncompressed_list|. Returns true if the format of the compressed whitelist | |
57 // is valid, | |
58 // false otherwise. | |
wtc
2014/08/20 02:52:07
Nit: please reformat this comment block.
Eran Messeri
2014/09/02 12:20:22
Done, I blame git-cl format for that :)
| |
59 NET_EXPORT_PRIVATE bool UncompressEVWhitelist( | |
60 const std::string& compressed_whitelist, | |
61 std::set<std::string>* uncompressed_list); | |
62 | |
63 // Sets the given |ev_whitelist| into the global context. | |
64 // Note that |ev_whitelist| will be empty after this call as the implementation | |
65 // is using set::swap() to efficiently switch the sets. | |
wtc
2014/08/20 02:52:07
IMPORTANT: are you sure this is true? The |ev_whit
Eran Messeri
2014/09/02 12:20:23
My bad, it was supposed to be passed by (non-const
| |
66 NET_EXPORT_PRIVATE void SetEVWhitelistData(std::set<std::string> ev_whitelist); | |
wtc
2014/08/20 02:52:07
This function is only used by SetEVWhitelistFromFi
Eran Messeri
2014/09/02 12:20:23
It's meant to be used from a test I did not write.
| |
67 | |
68 } // namespace internal | |
69 | |
70 // Sets the global EV certificate hashes whitelist from | |
71 // |compressed_whitelist_file| in the global context, after uncompressing it. | |
72 // If the data in |compressed_whitelist_file| is not a valid compressed | |
73 // whitelist, does nothing. | |
74 NET_EXPORT void SetEVWhitelistFromFile( | |
75 const base::FilePath& compressed_whitelist_file); | |
76 | |
77 // Returns true if the |certificate_hash| appears in the EV certificate hashes | |
78 // whitelist. | |
79 NET_EXPORT bool IsCertificateHashInWhitelist( | |
80 const std::string& certificate_hash); | |
81 | |
82 } // namespace ct | |
83 | |
84 } // namespace net | |
85 | |
86 #endif // NET_CERT_CT_EV_WHITELIST_H_ | |
OLD | NEW |