OLD | NEW |
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 Loading... |
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 IPAddress::IPAddressBytes& mask, |
| 108 unsigned prefix_length) { |
108 size_t zero_bits = mask.size() * CHAR_BIT - prefix_length; | 109 size_t zero_bits = mask.size() * CHAR_BIT - prefix_length; |
109 size_t zero_bytes = zero_bits / CHAR_BIT; | 110 size_t zero_bytes = zero_bits / CHAR_BIT; |
110 std::vector<uint8_t> zeros(zero_bytes, 0); | 111 std::vector<uint8_t> zeros(zero_bytes, 0); |
111 if (memcmp(zeros.data(), mask.data() + mask.size() - zero_bytes, zero_bytes)) | 112 if (memcmp(zeros.data(), mask.data() + mask.size() - zero_bytes, zero_bytes)) |
112 return false; | 113 return false; |
113 size_t leftover_bits = zero_bits % CHAR_BIT; | 114 size_t leftover_bits = zero_bits % CHAR_BIT; |
114 if (leftover_bits) { | 115 if (leftover_bits) { |
115 uint8_t b = mask[mask.size() - zero_bytes - 1]; | 116 uint8_t b = mask[mask.size() - zero_bytes - 1]; |
116 for (size_t i = 0; i < leftover_bits; ++i) { | 117 for (size_t i = 0; i < leftover_bits; ++i) { |
117 if (b & (1 << i)) | 118 if (b & (1 << i)) |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 549 |
549 return false; | 550 return false; |
550 } | 551 } |
551 | 552 |
552 int NameConstraints::ConstrainedNameTypes() const { | 553 int NameConstraints::ConstrainedNameTypes() const { |
553 return (permitted_subtrees_.present_name_types | | 554 return (permitted_subtrees_.present_name_types | |
554 excluded_subtrees_.present_name_types); | 555 excluded_subtrees_.present_name_types); |
555 } | 556 } |
556 | 557 |
557 } // namespace net | 558 } // namespace net |
OLD | NEW |