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

Side by Side Diff: net/cert/internal/name_constraints.cc

Issue 2881673002: Avoid heap allocations in IPAddress (Closed)
Patch Set: New constructor Created 3 years, 7 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
« no previous file with comments | « net/base/ip_address_unittest.cc ('k') | net/dns/mdns_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "net/cert/internal/name_constraints.h" 5 #include "net/cert/internal/name_constraints.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 name[name.size() - dns_constraint.size() - 1] == '.') { 97 name[name.size() - dns_constraint.size() - 1] == '.') {
98 return true; 98 return true;
99 } 99 }
100 // Trailing text matches, but not in a subtree (e.g., "foobar.com" is not a 100 // Trailing text matches, but not in a subtree (e.g., "foobar.com" is not a
101 // match for "bar.com"). 101 // match for "bar.com").
102 return false; 102 return false;
103 } 103 }
104 104
105 // Return true if the bitmask |mask| contains only zeros after the first 105 // Return true if the bitmask |mask| contains only zeros after the first
106 // |prefix_length| bits. 106 // |prefix_length| bits.
107 bool IsSuffixZero(const std::vector<uint8_t>& mask, unsigned prefix_length) { 107 bool IsSuffixZero(const IPAddressBytes& mask, unsigned prefix_length) {
108 size_t zero_bits = mask.size() * CHAR_BIT - prefix_length; 108 size_t zero_bits = mask.size() * CHAR_BIT - prefix_length;
109 size_t zero_bytes = zero_bits / CHAR_BIT; 109 size_t zero_bytes = zero_bits / CHAR_BIT;
110 std::vector<uint8_t> zeros(zero_bytes, 0); 110 std::vector<uint8_t> zeros(zero_bytes, 0);
111 if (memcmp(zeros.data(), mask.data() + mask.size() - zero_bytes, zero_bytes)) 111 if (memcmp(zeros.data(), mask.data() + mask.size() - zero_bytes, zero_bytes))
112 return false; 112 return false;
113 size_t leftover_bits = zero_bits % CHAR_BIT; 113 size_t leftover_bits = zero_bits % CHAR_BIT;
114 if (leftover_bits) { 114 if (leftover_bits) {
115 uint8_t b = mask[mask.size() - zero_bytes - 1]; 115 uint8_t b = mask[mask.size() - zero_bytes - 1];
116 for (size_t i = 0; i < leftover_bits; ++i) { 116 for (size_t i = 0; i < leftover_bits; ++i) {
117 if (b & (1 << i)) 117 if (b & (1 << i))
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 548
549 return false; 549 return false;
550 } 550 }
551 551
552 int NameConstraints::ConstrainedNameTypes() const { 552 int NameConstraints::ConstrainedNameTypes() const {
553 return (permitted_subtrees_.present_name_types | 553 return (permitted_subtrees_.present_name_types |
554 excluded_subtrees_.present_name_types); 554 excluded_subtrees_.present_name_types);
555 } 555 }
556 556
557 } // namespace net 557 } // namespace net
OLDNEW
« no previous file with comments | « net/base/ip_address_unittest.cc ('k') | net/dns/mdns_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698