| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ct_serialization.h" | 5 #include "net/cert/ct_serialization.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> |
| 10 |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 | 12 |
| 11 namespace net { | 13 namespace net { |
| 12 | 14 |
| 13 namespace ct { | 15 namespace ct { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // Note: length is always specified in bytes. | 19 // Note: length is always specified in bytes. |
| 18 // Signed Certificate Timestamp (SCT) Version length | 20 // Signed Certificate Timestamp (SCT) Version length |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 base::StringPiece log_id; | 355 base::StringPiece log_id; |
| 354 base::StringPiece extensions; | 356 base::StringPiece extensions; |
| 355 if (!ReadFixedBytes(kLogIdLength, input, &log_id) || | 357 if (!ReadFixedBytes(kLogIdLength, input, &log_id) || |
| 356 !ReadUint(kTimestampLength, input, ×tamp) || | 358 !ReadUint(kTimestampLength, input, ×tamp) || |
| 357 !ReadVariableBytes(kExtensionsLengthBytes, input, | 359 !ReadVariableBytes(kExtensionsLengthBytes, input, |
| 358 &extensions) || | 360 &extensions) || |
| 359 !DecodeDigitallySigned(input, &result->signature)) { | 361 !DecodeDigitallySigned(input, &result->signature)) { |
| 360 return false; | 362 return false; |
| 361 } | 363 } |
| 362 | 364 |
| 363 if (timestamp > static_cast<uint64_t>(kint64max)) { | 365 if (timestamp > static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) { |
| 364 DVLOG(1) << "Timestamp value too big to cast to int64_t: " << timestamp; | 366 DVLOG(1) << "Timestamp value too big to cast to int64_t: " << timestamp; |
| 365 return false; | 367 return false; |
| 366 } | 368 } |
| 367 | 369 |
| 368 log_id.CopyToString(&result->log_id); | 370 log_id.CopyToString(&result->log_id); |
| 369 extensions.CopyToString(&result->extensions); | 371 extensions.CopyToString(&result->extensions); |
| 370 result->timestamp = | 372 result->timestamp = |
| 371 base::Time::UnixEpoch() + | 373 base::Time::UnixEpoch() + |
| 372 base::TimeDelta::FromMilliseconds(static_cast<int64_t>(timestamp)); | 374 base::TimeDelta::FromMilliseconds(static_cast<int64_t>(timestamp)); |
| 373 | 375 |
| 374 output->swap(result); | 376 output->swap(result); |
| 375 return true; | 377 return true; |
| 376 } | 378 } |
| 377 | 379 |
| 378 bool EncodeSCTListForTesting(const base::StringPiece& sct, | 380 bool EncodeSCTListForTesting(const base::StringPiece& sct, |
| 379 std::string* output) { | 381 std::string* output) { |
| 380 std::string encoded_sct; | 382 std::string encoded_sct; |
| 381 return WriteVariableBytes(kSerializedSCTLengthBytes, sct, &encoded_sct) && | 383 return WriteVariableBytes(kSerializedSCTLengthBytes, sct, &encoded_sct) && |
| 382 WriteVariableBytes(kSCTListLengthBytes, encoded_sct, output); | 384 WriteVariableBytes(kSCTListLengthBytes, encoded_sct, output); |
| 383 } | 385 } |
| 384 | 386 |
| 385 } // namespace ct | 387 } // namespace ct |
| 386 | 388 |
| 387 } // namespace net | 389 } // namespace net |
| OLD | NEW |