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

Unified Diff: net/tools/domain_security_preload_generator/bit_writer.cc

Issue 2551153003: Add static domain security state generator tool. (Closed)
Patch Set: Fix iOS? Created 4 years 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: net/tools/domain_security_preload_generator/bit_writer.cc
diff --git a/net/tools/domain_security_preload_generator/bit_writer.cc b/net/tools/domain_security_preload_generator/bit_writer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fa4384235fdf35ddd96969e43b8396601dd9b402
--- /dev/null
+++ b/net/tools/domain_security_preload_generator/bit_writer.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2016 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.
+
+#include "net/tools/domain_security_preload_generator/bit_writer.h"
+
+#include "base/logging.h"
+
+namespace net {
+
+namespace transport_security_state {
+
+BitWriter::BitWriter() {}
+
+BitWriter::~BitWriter() {}
+
+void BitWriter::WriteBits(uint32_t bits, uint8_t number_of_bits) {
+ DCHECK(number_of_bits <= 32);
+ for (uint8_t i = 1; i <= number_of_bits; i++) {
+ uint8_t bit = 1 & (bits >> (number_of_bits - i));
+ WriteBit(bit);
+ }
+}
+
+void BitWriter::WriteBit(uint8_t bit) {
+ current_byte_ |= bit << (7 - used_);
+ used_++;
+ position_++;
+
+ if (used_ == 8) {
+ Flush();
+ }
+}
+
+void BitWriter::Flush() {
+ bytes_.push_back(current_byte_);
+
+ used_ = 0;
+ current_byte_ = 0;
+}
+
+uint8_t BitWriter::BitLength(uint32_t input) const {
+ uint8_t number_of_bits = 0;
+ while (input != 0) {
+ number_of_bits++;
+ input >>= 1;
+ }
+ return number_of_bits;
+}
+
+} // namespace transport_security_state
+
+} // namespace net
« no previous file with comments | « net/tools/domain_security_preload_generator/bit_writer.h ('k') | net/tools/domain_security_preload_generator/cert_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698