Index: media/webm/webm_crypt_helpers.cc |
diff --git a/media/webm/webm_crypt_helpers.cc b/media/webm/webm_crypt_helpers.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8896cbca20544942f35b0b876c53ca62397daf0d |
--- /dev/null |
+++ b/media/webm/webm_crypt_helpers.cc |
@@ -0,0 +1,49 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/webm/webm_crypt_helpers.h" |
xhwang
2012/08/29 05:08:14
How about rename this to "webm_crypto_helpers.h",
ddorwin
2012/09/01 16:46:41
Agreed. Is there a reason you chose "crypt"?
fgalligan1
2013/03/09 01:10:59
Done.
fgalligan1
2013/03/09 01:10:59
Done.
|
+ |
+#include "base/logging.h" |
ddorwin
2012/09/01 16:46:41
Not needed?
|
+#include "base/sys_byteorder.h" |
+#include "media/base/decrypt_config.h" |
+#include "media/crypto/decryptor_helpers.h" |
+#include "media/webm/webm_constants.h" |
+ |
+namespace media { |
+ |
+scoped_refptr<DecoderBuffer> WebMCopyBufferCheckIfEncrypted( |
ddorwin
2012/09/01 16:46:41
This function does not "check if encrypted". So, i
fgalligan1
2013/03/09 01:10:59
Renamed.
|
+ const uint8* data, int data_size, |
+ const uint8* key_id, int key_id_size) { |
+ scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( |
+ data + kWebMHmacSize, data_size - kWebMHmacSize); |
ddorwin
2012/09/01 16:46:41
line breaks and alignment seem questionable.
fgalligan1
2013/03/09 01:10:59
Removed.
|
+ CHECK(encrypted_buffer); |
+ |
+ uint8 signal_byte = data[kWebMHmacSize]; |
+ int data_offset = sizeof(signal_byte); |
ddorwin
2012/09/01 16:46:41
const int kDataOffset?
"data_offset" is not direct
fgalligan1
2013/03/09 01:10:59
Changed to frame_offset.
|
+ |
+ // 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 & kWebMFlagEncryptedFrame) { |
+ uint64 network_iv; |
ddorwin
2012/09/01 16:46:41
Might comment "IV is only present for encrypted fr
fgalligan1
2013/03/09 01:10:59
Done.
|
+ memcpy(&network_iv, data + kWebMHmacSize + data_offset, sizeof(network_iv)); |
+ const uint64 iv = base::NetToHost64(network_iv); |
+ counter_block_str = |
+ GenerateCounterBlock(iv); |
ddorwin
2012/09/01 16:46:41
on same line as above
|
+ data_offset += sizeof(iv); |
+ } |
+ |
+ encrypted_buffer->SetDecryptConfig( |
+ scoped_ptr<DecryptConfig>(new DecryptConfig( |
+ std::string(reinterpret_cast<const char*>(key_id), key_id_size), |
+ counter_block_str, |
+ std::string(reinterpret_cast<const char*>(data), kWebMHmacSize), |
+ data_offset, |
+ std::vector<SubsampleEntry>()))); |
+ return encrypted_buffer; |
+} |
+ |
+} // media |
xhwang
2012/08/29 05:08:14
// namespace media
fgalligan1
2013/03/09 01:10:59
Done.
|