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

Unified Diff: chrome/browser/net/bit_stream_reader.h

Issue 547603002: Certificate Transparency: Code for unpacking EV cert hashes whitelist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Catching up with base/files change on master Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/bit_stream_reader.h
diff --git a/chrome/browser/net/bit_stream_reader.h b/chrome/browser/net/bit_stream_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..1d9420f7503f3504a78fa53a7ff573b0036a019f
--- /dev/null
+++ b/chrome/browser/net/bit_stream_reader.h
@@ -0,0 +1,54 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NET_BIT_STREAM_READER_H_
+#define CHROME_BROWSER_NET_BIT_STREAM_READER_H_
+
+#include <stdint.h>
+
+#include "base/strings/string_piece.h"
+
+namespace internal {
+
+// A class for reading individual bits from a buffer of bytes they are packed
+// into. Bits are read MSB-first from the stream.
+// It is limited to 64-bit reads and is inefficient as a design choice - Since
+// it is used infrequently to unpack the Golomb-coded EV certificate hashes
+// whitelist in a blocking thread.
Ryan Sleevi 2014/10/20 19:18:24 This comment needs rewording. You shouldn't discus
Eran Messeri 2014/10/21 14:59:59 Done.
+class BitStreamReader {
+ public:
+ explicit BitStreamReader(const base::StringPiece& source);
+
+ // Reads unary-encoded number into |out|. Returns true if
+ // there was at least one bit to read, false otherwise.
+ bool ReadUnaryEncoding(uint64_t* out);
+
+ // Reads |num_bits| (up to 64) into |out|. |out| is filled from the MSB to the
+ // LSB. If |num_bits| is less than 64, the most significant |64 - num_bits|
+ // bits are unused and left as zeros. Returns true if the stream had the
+ // requested |num_bits|, false otherwise.
+ bool ReadBits(uint8_t num_bits, uint64_t* out);
+
+ // Returns the number of bits left in the stream.
+ uint64_t BitsLeft() const;
+
+ private:
+ // Reads a single bit. Within a byte, the bits are read from the MSB to the
+ // LSB.
+ uint8_t ReadBit();
+
+ const base::StringPiece source_;
+
+ // Index of the byte currently being read from.
+ uint64_t current_byte_;
+
+ // Index of the last bit read within |current_byte_|. Since bits are read
+ // from the MSB to the LSB, this value is initialized to 7 and decremented
+ // after each read.
+ int8 current_bit_;
+};
Ryan Sleevi 2014/10/20 19:18:25 DISALLOW_COPY_AND_ASSIGN
Eran Messeri 2014/10/21 14:59:59 Done.
+
+} // namespace internal
+
+#endif // CHROME_BROWSER_NET_BIT_STREAM_READER_H_

Powered by Google App Engine
This is Rietveld 408576698