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

Side by Side Diff: net/tools/transport_security_state_generator/trie/trie_bit_buffer.h

Issue 2660793002: Add transport security state generator tests. (Closed)
Patch Set: export method for tests Created 3 years, 10 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
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_ 5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_ 6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h"
12 #include "net/tools/transport_security_state_generator/huffman/huffman_builder.h " 13 #include "net/tools/transport_security_state_generator/huffman/huffman_builder.h "
13 14
14 namespace net { 15 namespace net {
15 16
16 namespace transport_security_state { 17 namespace transport_security_state {
17 18
18 class BitWriter; 19 class BitWriter;
19 20
20 // TrieBitBuffer acts as a buffer for TrieWriter. It can be used to write bits, 21 // TrieBitBuffer acts as a buffer for TrieWriter. It can be used to write bits,
21 // characters, and positions. The characters are stored as their 22 // characters, and positions. The characters are stored as their
(...skipping 11 matching lines...) Expand all
33 // buffer. 34 // buffer.
34 void WriteBits(uint32_t bits, uint8_t number_of_bits); 35 void WriteBits(uint32_t bits, uint8_t number_of_bits);
35 36
36 // Write a position to the buffer. Actually writes the difference between 37 // Write a position to the buffer. Actually writes the difference between
37 // |position| and |*last_position|. |*last_position| will be updated to equal 38 // |position| and |*last_position|. |*last_position| will be updated to equal
38 // the input |position|. 39 // the input |position|.
39 void WritePosition(uint32_t position, int32_t* last_position); 40 void WritePosition(uint32_t position, int32_t* last_position);
40 41
41 // Writes the character in |byte| to the buffer using its Huffman 42 // Writes the character in |byte| to the buffer using its Huffman
42 // representation in |table|. Optionally tracks usage of the character in 43 // representation in |table|. Optionally tracks usage of the character in
43 // |*huffman_builder|. 44 // |*huffman_builder|. Returns false when |byte| is not found in |table|.
44 void WriteChar(uint8_t byte, 45 bool WriteChar(uint8_t byte,
45 const HuffmanRepresentationTable& table, 46 const HuffmanRepresentationTable& table,
46 HuffmanBuilder* huffman_builder); 47 HuffmanBuilder* huffman_builder);
47 48
48 // Writes the entire buffer to |*writer|. Returns the position |*writer| was 49 // Writes the entire buffer to |*writer|. Returns the position |*writer| was
49 // at before the buffer was written to it. 50 // at before the buffer was written to it.
50 uint32_t WriteToBitWriter(BitWriter* writer); 51 uint32_t WriteToBitWriter(BitWriter* writer);
51 52
52 // Appends the buffered bits in |current_byte_| to |elements_|. Empty bits 53 // Appends the buffered bits in |current_byte_| to |elements_|. No padding
53 // are filled with zero's. 54 // will occur.
54 void Flush(); 55 void Flush();
55 56
56 private: 57 private:
57 // Represents either the |number_of_bits| least-significant bits in |bits| or 58 // Represents either the |number_of_bits| least-significant bits in |bits| or
58 // a position (offset) in the trie. 59 // a position (offset) in the trie.
59 struct BitsOrPosition { 60 struct BitsOrPosition {
60 uint8_t bits; 61 uint8_t bits;
61 uint8_t number_of_bits; 62 uint8_t number_of_bits;
62 uint32_t position; 63 uint32_t position;
63 }; 64 };
64 65
65 // Returns the minimum number of bits needed to represent |input|. 66 // Returns the minimum number of bits needed to represent |input|.
66 uint8_t BitLength(uint32_t input) const; 67 uint8_t BitLength(uint32_t input) const;
67 68
68 // Append a new element to |elements_|. 69 // Append a new element to |elements_|.
69 void AppendBitsElement(uint8_t bits, uint8_t number_of_bits); 70 void AppendBitsElement(uint8_t bits, uint8_t number_of_bits);
70 void AppendPositionElement(uint32_t position); 71 void AppendPositionElement(uint32_t position);
71 72
72 // Buffers bits until they fill a whole byte. 73 // Buffers bits until they fill a whole byte.
73 uint8_t current_byte_ = 0; 74 uint8_t current_byte_ = 0;
74 75
75 // The number of bits currently in |current_byte_|. 76 // The number of bits currently in |current_byte_|.
76 uint32_t used_ = 0; 77 uint32_t used_ = 0;
77 78
78 std::vector<BitsOrPosition> elements_; 79 std::vector<BitsOrPosition> elements_;
80
81 DISALLOW_COPY_AND_ASSIGN(TrieBitBuffer);
79 }; 82 };
80 83
81 } // namespace transport_security_state 84 } // namespace transport_security_state
82 85
83 } // namespace net 86 } // namespace net
84 87
85 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_ 88 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698