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

Side by Side Diff: net/cert/ct_serialization.cc

Issue 1951233003: Consistent SignedCertificateTimestamp::Version and SignedTreeHead::Version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/cert/ct_objects_extractor_unittest.cc ('k') | net/cert/signed_certificate_timestamp.h » ('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 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 <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 static void WriteTimeSinceEpoch(const base::Time& timestamp, 332 static void WriteTimeSinceEpoch(const base::Time& timestamp,
333 std::string* output) { 333 std::string* output) {
334 base::TimeDelta time_since_epoch = timestamp - base::Time::UnixEpoch(); 334 base::TimeDelta time_since_epoch = timestamp - base::Time::UnixEpoch();
335 WriteUint(kTimestampLength, time_since_epoch.InMilliseconds(), output); 335 WriteUint(kTimestampLength, time_since_epoch.InMilliseconds(), output);
336 } 336 }
337 337
338 bool EncodeV1SCTSignedData(const base::Time& timestamp, 338 bool EncodeV1SCTSignedData(const base::Time& timestamp,
339 const std::string& serialized_log_entry, 339 const std::string& serialized_log_entry,
340 const std::string& extensions, 340 const std::string& extensions,
341 std::string* output) { 341 std::string* output) {
342 WriteUint(kVersionLength, SignedCertificateTimestamp::SCT_VERSION_1, 342 WriteUint(kVersionLength, SignedCertificateTimestamp::V1,
343 output); 343 output);
344 WriteUint(kSignatureTypeLength, SIGNATURE_TYPE_CERTIFICATE_TIMESTAMP, 344 WriteUint(kSignatureTypeLength, SIGNATURE_TYPE_CERTIFICATE_TIMESTAMP,
345 output); 345 output);
346 WriteTimeSinceEpoch(timestamp, output); 346 WriteTimeSinceEpoch(timestamp, output);
347 // NOTE: serialized_log_entry must already be serialized and contain the 347 // NOTE: serialized_log_entry must already be serialized and contain the
348 // length as the prefix. 348 // length as the prefix.
349 WriteEncodedBytes(serialized_log_entry, output); 349 WriteEncodedBytes(serialized_log_entry, output);
350 return WriteVariableBytes(kExtensionsLengthBytes, extensions, output); 350 return WriteVariableBytes(kExtensionsLengthBytes, extensions, output);
351 } 351 }
352 352
(...skipping 23 matching lines...) Expand all
376 } 376 }
377 377
378 bool DecodeSignedCertificateTimestamp( 378 bool DecodeSignedCertificateTimestamp(
379 base::StringPiece* input, 379 base::StringPiece* input,
380 scoped_refptr<SignedCertificateTimestamp>* output) { 380 scoped_refptr<SignedCertificateTimestamp>* output) {
381 scoped_refptr<SignedCertificateTimestamp> result( 381 scoped_refptr<SignedCertificateTimestamp> result(
382 new SignedCertificateTimestamp()); 382 new SignedCertificateTimestamp());
383 unsigned version; 383 unsigned version;
384 if (!ReadUint(kVersionLength, input, &version)) 384 if (!ReadUint(kVersionLength, input, &version))
385 return false; 385 return false;
386 if (version != SignedCertificateTimestamp::SCT_VERSION_1) { 386 if (version != SignedCertificateTimestamp::V1) {
387 DVLOG(1) << "Unsupported/invalid version " << version; 387 DVLOG(1) << "Unsupported/invalid version " << version;
388 return false; 388 return false;
389 } 389 }
390 390
391 result->version = SignedCertificateTimestamp::SCT_VERSION_1; 391 result->version = SignedCertificateTimestamp::V1;
392 base::StringPiece log_id; 392 base::StringPiece log_id;
393 base::StringPiece extensions; 393 base::StringPiece extensions;
394 if (!ReadFixedBytes(kLogIdLength, input, &log_id) || 394 if (!ReadFixedBytes(kLogIdLength, input, &log_id) ||
395 !ReadTimeSinceEpoch(input, &result->timestamp) || 395 !ReadTimeSinceEpoch(input, &result->timestamp) ||
396 !ReadVariableBytes(kExtensionsLengthBytes, input, &extensions) || 396 !ReadVariableBytes(kExtensionsLengthBytes, input, &extensions) ||
397 !DecodeDigitallySigned(input, &result->signature)) { 397 !DecodeDigitallySigned(input, &result->signature)) {
398 return false; 398 return false;
399 } 399 }
400 400
401 log_id.CopyToString(&result->log_id); 401 log_id.CopyToString(&result->log_id);
402 extensions.CopyToString(&result->extensions); 402 extensions.CopyToString(&result->extensions);
403 output->swap(result); 403 output->swap(result);
404 return true; 404 return true;
405 } 405 }
406 406
407 bool EncodeSCTListForTesting(const base::StringPiece& sct, 407 bool EncodeSCTListForTesting(const base::StringPiece& sct,
408 std::string* output) { 408 std::string* output) {
409 std::string encoded_sct; 409 std::string encoded_sct;
410 return WriteVariableBytes(kSerializedSCTLengthBytes, sct, &encoded_sct) && 410 return WriteVariableBytes(kSerializedSCTLengthBytes, sct, &encoded_sct) &&
411 WriteVariableBytes(kSCTListLengthBytes, encoded_sct, output); 411 WriteVariableBytes(kSCTListLengthBytes, encoded_sct, output);
412 } 412 }
413 413
414 } // namespace ct 414 } // namespace ct
415 415
416 } // namespace net 416 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/ct_objects_extractor_unittest.cc ('k') | net/cert/signed_certificate_timestamp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698