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

Side by Side Diff: components/safe_browsing_db/v4_rice.h

Issue 2228393003: PVer4: DecodeHashes needs to sort the output of the Rice decoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_checksum
Patch Set: Use a vector to decode and sort uint32_t values. re-interpret the memory of that vector as raw hash… Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 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 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 // Rice-Golomb decoder for blacklist updates. 5 // Rice-Golomb decoder for blacklist updates.
6 // Details at: https://en.wikipedia.org/wiki/Golomb_coding 6 // Details at: https://en.wikipedia.org/wiki/Golomb_coding
7 7
8 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_ 8 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_
9 #define COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_ 9 #define COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_
10 10
11 #include <ostream> 11 #include <ostream>
12 #include <string> 12 #include <string>
13 #include <vector>
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 15
15 #if defined(USE_SYSTEM_PROTOBUF) 16 #if defined(USE_SYSTEM_PROTOBUF)
16 #include <google/protobuf/repeated_field.h> 17 #include <google/protobuf/repeated_field.h>
17 #else 18 #else
18 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" 19 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
19 #endif 20 #endif
20 21
21 namespace safe_browsing { 22 namespace safe_browsing {
22 23
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 public: 59 public:
59 // Decodes the Rice-encoded string in |encoded_data| as a list of integers 60 // Decodes the Rice-encoded string in |encoded_data| as a list of integers
60 // and stores them in |out|. |rice_parameter| is the exponent of 2 for 61 // and stores them in |out|. |rice_parameter| is the exponent of 2 for
61 // calculating 'M', |first_value| is the first value in the output sequence, 62 // calculating 'M', |first_value| is the first value in the output sequence,
62 // |num_entries| is the number of subsequent encoded entries. Each decoded 63 // |num_entries| is the number of subsequent encoded entries. Each decoded
63 // value is a positive offset from the previous value. 64 // value is a positive offset from the previous value.
64 // So, for instance, if the unencoded sequence is: [3, 7, 25], then 65 // So, for instance, if the unencoded sequence is: [3, 7, 25], then
65 // |first_value| = 3, |num_entries| = 2 and decoding the |encoded_data| will 66 // |first_value| = 3, |num_entries| = 2 and decoding the |encoded_data| will
66 // produce the offsets: [4, 18]. 67 // produce the offsets: [4, 18].
67 static V4DecodeResult DecodeIntegers( 68 static V4DecodeResult DecodeIntegers(
68 const ::google::protobuf::int32 first_value, 69 const ::google::protobuf::int64 first_value,
69 const ::google::protobuf::int32 rice_parameter, 70 const ::google::protobuf::int32 rice_parameter,
70 const ::google::protobuf::int32 num_entries, 71 const ::google::protobuf::int32 num_entries,
71 const std::string& encoded_data, 72 const std::string& encoded_data,
72 ::google::protobuf::RepeatedField<::google::protobuf::int32>* out); 73 ::google::protobuf::RepeatedField<::google::protobuf::int32>* out);
73 74
74 // Decodes the Rice-encoded string in |encoded_data| as a string of 4-byte 75 // Decodes the Rice-encoded string in |encoded_data| as a string of 4-byte
75 // hash prefixes and stores them in |out|. The rest of the arguments are the 76 // hash prefixes and stores them in |out|. The rest of the arguments are the
76 // same as for |DecodeIntegers|. 77 // same as for |DecodeIntegers|.
77 static V4DecodeResult DecodeBytes( 78 static V4DecodeResult DecodeBytes(
78 const ::google::protobuf::int32 first_value, 79 const ::google::protobuf::int64 first_value,
79 const ::google::protobuf::int32 rice_parameter, 80 const ::google::protobuf::int32 rice_parameter,
80 const ::google::protobuf::int32 num_entries, 81 const ::google::protobuf::int32 num_entries,
81 const std::string& encoded_data, 82 const std::string& encoded_data,
82 std::string* out); 83 std::vector<uint32_t>* out);
83 84
84 virtual ~V4RiceDecoder(); 85 virtual ~V4RiceDecoder();
85 86
86 std::string DebugString() const; 87 std::string DebugString() const;
87 88
88 private: 89 private:
89 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextWordWithNoData); 90 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextWordWithNoData);
90 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextBitsWithNoData); 91 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextBitsWithNoData);
91 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoData); 92 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoData);
92 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoEntries); 93 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoEntries);
93 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithSmallValues); 94 friend class V4RiceTest;
94 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithLargeValues);
95 95
96 // Validate some of the parameters passed to the decode methods. 96 // Validate some of the parameters passed to the decode methods.
97 static V4DecodeResult ValidateInput( 97 static V4DecodeResult ValidateInput(
98 const ::google::protobuf::int32 rice_parameter, 98 const ::google::protobuf::int32 rice_parameter,
99 const ::google::protobuf::int32 num_entries, 99 const ::google::protobuf::int32 num_entries,
100 const std::string& encoded_data); 100 const std::string& encoded_data);
101 101
102 // The |rice_parameter| is the exponent of 2 for calculating 'M', 102 // The |rice_parameter| is the exponent of 2 for calculating 'M',
103 // |num_entries| is the number of encoded entries in the |encoded_data| and 103 // |num_entries| is the number of encoded entries in the |encoded_data| and
104 // |encoded_data| is the Rice-encoded string to decode. 104 // |encoded_data| is the Rice-encoded string to decode.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // The 32-bit value read from |data_|. All bit reading operations operate on 147 // The 32-bit value read from |data_|. All bit reading operations operate on
148 // |current_word_|. 148 // |current_word_|.
149 uint32_t current_word_; 149 uint32_t current_word_;
150 }; 150 };
151 151
152 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder); 152 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder);
153 153
154 } // namespace safe_browsing 154 } // namespace safe_browsing
155 155
156 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_ 156 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_rice.cc » ('j') | components/safe_browsing_db/v4_rice.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698