Chromium Code Reviews| Index: media/webm/webm_cluster_parser.cc |
| diff --git a/media/webm/webm_cluster_parser.cc b/media/webm/webm_cluster_parser.cc |
| index e9ef93e3fb14c8bd29197f0e826dcff6c9bf25a1..e7d8cfd00ea2895b2d4c29830de0a6f59b9355d2 100644 |
| --- a/media/webm/webm_cluster_parser.cc |
| +++ b/media/webm/webm_cluster_parser.cc |
| @@ -220,12 +220,14 @@ bool WebMClusterParser::OnBlock(int track_num, int timecode, |
| // Every encrypted Block has an HMAC and IV prepended to it. Current encrypted |
| // WebM request for comments specification is here |
| // http://wiki.webmproject.org/encryption/webm-encryption-rfc |
| - bool encrypted = track_num == video_.track_num() && |
| - video_encryption_key_id_.get(); |
| - // If encrypted skip past the HMAC. Encrypted buffers must include the IV and |
| - // the encrypted frame because the decryptor will verify this data before |
| - // decryption. The HMAC and IV will be copied into DecryptConfig. |
| - int offset = (encrypted) ? kWebMHmacSize : 0; |
| + bool encrypted_stream = track_num == video_.track_num() && |
|
xhwang
2012/08/01 00:45:41
"encrypted_stream" is a noun. How about something
fgalligan1
2012/08/01 01:36:10
Done.
|
| + video_encryption_key_id_.get(); |
| + |
| + // If stream is encrypted skip past the HMAC. Encrypted buffers must include |
| + // the signal byte, the IV (if frame is encrypted) and |
| + // the frame because the decryptor will verify this data before decryption. |
| + // The HMAC and IV will be copied into DecryptConfig. |
| + int offset = (encrypted_stream) ? kWebMHmacSize : 0; |
| // The first bit of the flags is set when the block contains only keyframes. |
| // http://www.matroska.org/technical/specs/index.html |
| @@ -233,21 +235,34 @@ bool WebMClusterParser::OnBlock(int track_num, int timecode, |
| scoped_refptr<StreamParserBuffer> buffer = |
| StreamParserBuffer::CopyFrom(data + offset, size - offset, is_keyframe); |
| - if (encrypted) { |
| - uint64 network_iv; |
| - memcpy(&network_iv, data + kWebMHmacSize, sizeof(network_iv)); |
| - const uint64 iv = base::NetToHost64(network_iv); |
| + if (encrypted_stream) { |
| + int data_offset = 1; |
| + uint8 signal_byte = data[kWebMHmacSize]; |
|
xhwang
2012/08/01 00:45:41
How about moving "int data_offset = 1" after this
fgalligan1
2012/08/01 01:36:10
Done.
|
| + |
| + // Setting the DecryptConfig object of the buffer while leaving the |
| + // initialization vector empty will tell the decryptor that the frame is |
| + // unencrypted but integrity should still be checked. |
| + std::string counter_block_str; |
| + |
| + if (signal_byte & kWebMEncryptedFrame) { |
| + uint64 network_iv; |
| + memcpy(&network_iv, data + kWebMHmacSize + 1, sizeof(network_iv)); |
|
xhwang
2012/08/01 00:45:41
s/1/data_offset/
fgalligan1
2012/08/01 01:36:10
Done.
|
| + const uint64 iv = base::NetToHost64(network_iv); |
| + |
| + scoped_array<uint8> counter_block(GenerateCounterBlock(iv)); |
| + counter_block_str.assign( |
| + reinterpret_cast<const char*>(counter_block.get()), |
| + DecryptConfig::kDecryptionKeySize); |
|
xhwang
2012/08/01 00:45:41
This code will be much easier if GenerateCounterBl
fgalligan1
2012/08/01 01:36:10
Done.
|
| + data_offset += sizeof(iv); |
| + } |
| - scoped_array<uint8> counter_block(GenerateCounterBlock(iv)); |
| buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( |
| std::string( |
| reinterpret_cast<const char*>(video_encryption_key_id_.get()), |
| video_encryption_key_id_size_), |
| - std::string( |
| - reinterpret_cast<const char*>(counter_block.get()), |
| - DecryptConfig::kDecryptionKeySize), |
| + counter_block_str, |
| std::string(reinterpret_cast<const char*>(data), kWebMHmacSize), |
| - sizeof(iv), |
| + data_offset, |
| std::vector<SubsampleEntry>()))); |
| } |