Chromium Code Reviews| Index: net/cert/ct_serialization.cc |
| diff --git a/net/cert/ct_serialization.cc b/net/cert/ct_serialization.cc |
| index 2de83087260f8828a81a44e65f719eeb5bd8ebe9..d64c839f2ed95c61555ce85afe56ebffb340d7af 100644 |
| --- a/net/cert/ct_serialization.cc |
| +++ b/net/cert/ct_serialization.cc |
| @@ -19,22 +19,25 @@ namespace ct { |
| namespace { |
| // Note: length is always specified in bytes. |
| -// Signed Certificate Timestamp (SCT) Version length |
| +// CT protocol version length |
| const size_t kVersionLength = 1; |
| +const size_t kSha256HashLength = 32; |
|
Eran Messeri
2016/05/04 10:29:23
This is redundant, you can use the definition from
Rob Percival
2016/05/05 15:45:31
Done.
|
| -// Members of a V1 SCT |
| -const size_t kLogIdLength = 32; |
| +// Common V1 struct members |
| const size_t kTimestampLength = 8; |
| +const size_t kLogEntryTypeLength = 2; |
| +const size_t kAsn1CertificateLengthBytes = 3; |
| +const size_t kTbsCertificateLengthBytes = 3; |
| const size_t kExtensionsLengthBytes = 2; |
| + |
| +// Members of a V1 SCT |
| +const size_t kLogIdLength = kSha256HashLength; |
| const size_t kHashAlgorithmLength = 1; |
| const size_t kSigAlgorithmLength = 1; |
| const size_t kSignatureLengthBytes = 2; |
| // Members of the digitally-signed struct of a V1 SCT |
| const size_t kSignatureTypeLength = 1; |
| -const size_t kLogEntryTypeLength = 2; |
| -const size_t kAsn1CertificateLengthBytes = 3; |
| -const size_t kTbsCertificateLengthBytes = 3; |
| const size_t kSCTListLengthBytes = 2; |
| const size_t kSerializedSCTLengthBytes = 2; |
| @@ -42,6 +45,10 @@ const size_t kSerializedSCTLengthBytes = 2; |
| // Members of digitally-signed struct of a STH |
| const size_t kTreeSizeLength = 8; |
| +// Members of a V1 MerkleTreeLeaf |
| +const size_t kMerkleLeafTypeLength = 1; |
| +const size_t kIssuerKeyHashLength = kSha256HashLength; |
| + |
| enum SignatureType { |
| SIGNATURE_TYPE_CERTIFICATE_TIMESTAMP = 0, |
| TREE_HASH = 1, |
| @@ -254,7 +261,7 @@ bool EncodePrecertLogEntry(const LogEntry& input, std::string* output) { |
| WriteEncodedBytes( |
| base::StringPiece( |
| reinterpret_cast<const char*>(input.issuer_key_hash.data), |
| - kLogIdLength), |
| + kIssuerKeyHashLength), |
| output); |
| return WriteVariableBytes(kTbsCertificateLengthBytes, |
| input.tbs_certificate, output); |
| @@ -335,6 +342,19 @@ static void WriteTimeSinceEpoch(const base::Time& timestamp, |
| WriteUint(kTimestampLength, time_since_epoch.InMilliseconds(), output); |
| } |
| +bool EncodeTreeLeaf(const MerkleTreeLeaf& leaf, std::string* output) { |
| + WriteUint(kVersionLength, MerkleTreeLeaf::VERSION_1, output); |
| + WriteUint(kMerkleLeafTypeLength, MerkleTreeLeaf::TYPE_TIMESTAMPED_ENTRY, |
| + output); |
| + WriteTimeSinceEpoch(leaf.timestamp, output); |
| + if (!EncodeLogEntry(leaf.log_entry, output)) |
| + return false; |
| + if (!WriteVariableBytes(kExtensionsLengthBytes, leaf.extensions, output)) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| bool EncodeV1SCTSignedData(const base::Time& timestamp, |
| const std::string& serialized_log_entry, |
| const std::string& extensions, |