Chromium Code Reviews| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/numerics/safe_math.h" | 6 #include "base/numerics/safe_math.h" |
| 7 #include "net/der/parse_values.h" | 7 #include "net/der/parse_values.h" |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 | 10 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 if (first_byte == 0 && !(second_byte & 0x80)) { | 159 if (first_byte == 0 && !(second_byte & 0x80)) { |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 *out = value; | 163 *out = value; |
| 164 return true; | 164 return true; |
| 165 } | 165 } |
| 166 | 166 |
| 167 bool ParseBitString(const Input& in, | |
| 168 Input* out_bytes, | |
| 169 uint8_t* out_unused_bits) { | |
| 170 ByteReader reader(in); | |
| 171 | |
| 172 // The first byte of the value gives the number of unused bits. | |
| 173 // It must be in the range 0 - 7 (or else the encoding is not minimal). | |
|
nharper
2015/07/21 23:23:47
cite spec (this is a requirement for BER, not just
eroman
2015/07/22 17:05:23
Done. I changed the comment to:
// From ITU-T X
| |
| 174 uint8_t unused_bits; | |
| 175 if (!reader.ReadByte(&unused_bits)) | |
| 176 return false; | |
| 177 if (unused_bits > 7) | |
| 178 return false; | |
| 179 | |
| 180 Input bytes; | |
| 181 if (!reader.ReadBytes(reader.BytesLeft(), &bytes)) | |
| 182 return false; // Not reachable. | |
| 183 | |
| 184 // Ensure that unused bits in the last byte are set to 0. | |
|
nharper
2015/07/21 23:23:47
cite spec (this is only a requirement for CER and
eroman
2015/07/22 17:05:23
Done. I added two citations for this section:
| |
| 185 if (unused_bits > 0) { | |
| 186 if (bytes.Length() == 0) | |
| 187 return false; | |
| 188 uint8_t last_byte = bytes.UnsafeData()[bytes.Length() - 1]; | |
| 189 | |
| 190 uint8_t mask = 0xFF >> (8 - unused_bits); | |
| 191 if ((mask & last_byte) != 0) | |
| 192 return false; | |
| 193 } | |
| 194 | |
| 195 *out_bytes = bytes; | |
| 196 *out_unused_bits = unused_bits; | |
| 197 return true; | |
| 198 } | |
| 199 | |
| 167 bool operator<(const GeneralizedTime& lhs, const GeneralizedTime& rhs) { | 200 bool operator<(const GeneralizedTime& lhs, const GeneralizedTime& rhs) { |
| 168 if (lhs.year != rhs.year) | 201 if (lhs.year != rhs.year) |
| 169 return lhs.year < rhs.year; | 202 return lhs.year < rhs.year; |
| 170 if (lhs.month != rhs.month) | 203 if (lhs.month != rhs.month) |
| 171 return lhs.month < rhs.month; | 204 return lhs.month < rhs.month; |
| 172 if (lhs.day != rhs.day) | 205 if (lhs.day != rhs.day) |
| 173 return lhs.day < rhs.day; | 206 return lhs.day < rhs.day; |
| 174 if (lhs.hours != rhs.hours) | 207 if (lhs.hours != rhs.hours) |
| 175 return lhs.hours < rhs.hours; | 208 return lhs.hours < rhs.hours; |
| 176 if (lhs.minutes != rhs.minutes) | 209 if (lhs.minutes != rhs.minutes) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 return false; | 293 return false; |
| 261 if (!ValidateGeneralizedTime(time)) | 294 if (!ValidateGeneralizedTime(time)) |
| 262 return false; | 295 return false; |
| 263 *value = time; | 296 *value = time; |
| 264 return true; | 297 return true; |
| 265 } | 298 } |
| 266 | 299 |
| 267 } // namespace der | 300 } // namespace der |
| 268 | 301 |
| 269 } // namespace net | 302 } // namespace net |
| OLD | NEW |