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

Unified Diff: media/crypto/aes_decryptor.cc

Issue 17408005: Refactored DecoderBuffer to use unix_hacker_style naming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@localrefactor
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: media/crypto/aes_decryptor.cc
diff --git a/media/crypto/aes_decryptor.cc b/media/crypto/aes_decryptor.cc
index 8136cadfb82751c1685d7cd6518a6552e19eb11c..4428b9667e5ae8552f90328ec1a60bcdc9c97d15 100644
--- a/media/crypto/aes_decryptor.cc
+++ b/media/crypto/aes_decryptor.cc
@@ -27,8 +27,7 @@ enum ClearBytesBufferSel {
};
static void CopySubsamples(const std::vector<SubsampleEntry>& subsamples,
- const ClearBytesBufferSel sel,
- const uint8* src,
+ const ClearBytesBufferSel sel, const uint8* src,
uint8* dst) {
for (size_t i = 0; i < subsamples.size(); i++) {
const SubsampleEntry& subsample = subsamples[i];
@@ -47,8 +46,8 @@ static void CopySubsamples(const std::vector<SubsampleEntry>& subsamples,
// data if decryption succeeded or NULL if decryption failed.
static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input,
crypto::SymmetricKey* key) {
- CHECK(input.GetDataSize());
- CHECK(input.GetDecryptConfig());
+ CHECK(input.get_data_size());
+ CHECK(input.get_decrypt_config());
CHECK(key);
crypto::Encryptor encryptor;
@@ -57,19 +56,19 @@ static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input,
return NULL;
}
- DCHECK_EQ(input.GetDecryptConfig()->iv().size(),
+ DCHECK_EQ(input.get_decrypt_config()->iv().size(),
static_cast<size_t>(DecryptConfig::kDecryptionKeySize));
- if (!encryptor.SetCounter(input.GetDecryptConfig()->iv())) {
+ if (!encryptor.SetCounter(input.get_decrypt_config()->iv())) {
DVLOG(1) << "Could not set counter block.";
return NULL;
}
- const int data_offset = input.GetDecryptConfig()->data_offset();
+ const int data_offset = input.get_decrypt_config()->data_offset();
const char* sample =
- reinterpret_cast<const char*>(input.GetData() + data_offset);
- int sample_size = input.GetDataSize() - data_offset;
+ reinterpret_cast<const char*>(input.get_data() + data_offset);
+ int sample_size = input.get_data_size() - data_offset;
- if (input.GetDecryptConfig()->subsamples().empty()) {
+ if (input.get_decrypt_config()->subsamples().empty()) {
std::string decrypted_text;
base::StringPiece encrypted_text(sample, sample_size);
if (!encryptor.Decrypt(encrypted_text, &decrypted_text)) {
@@ -78,13 +77,13 @@ static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input,
}
// TODO(xhwang): Find a way to avoid this data copy.
- return DecoderBuffer::CopyFrom(
+ return DecoderBuffer::copy_from(
reinterpret_cast<const uint8*>(decrypted_text.data()),
decrypted_text.size());
}
const std::vector<SubsampleEntry>& subsamples =
- input.GetDecryptConfig()->subsamples();
+ input.get_decrypt_config()->subsamples();
int total_clear_size = 0;
int total_encrypted_size = 0;
@@ -116,11 +115,11 @@ static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input,
return NULL;
}
- scoped_refptr<DecoderBuffer> output = DecoderBuffer::CopyFrom(
+ scoped_refptr<DecoderBuffer> output = DecoderBuffer::copy_from(
reinterpret_cast<const uint8*>(sample), sample_size);
CopySubsamples(subsamples, kDstContainsClearBytes,
reinterpret_cast<const uint8*>(decrypted_text.data()),
- output->GetWritableData());
+ output->get_writable_data());
return output;
}
@@ -131,12 +130,9 @@ AesDecryptor::AesDecryptor(const KeyAddedCB& key_added_cb,
: key_added_cb_(key_added_cb),
key_error_cb_(key_error_cb),
key_message_cb_(key_message_cb),
- need_key_cb_(need_key_cb) {
-}
+ need_key_cb_(need_key_cb) {}
-AesDecryptor::~AesDecryptor() {
- STLDeleteValues(&key_map_);
-}
+AesDecryptor::~AesDecryptor() { STLDeleteValues(&key_map_); }
bool AesDecryptor::GenerateKeyRequest(const std::string& type,
const uint8* init_data,
@@ -147,18 +143,16 @@ bool AesDecryptor::GenerateKeyRequest(const std::string& type,
// just fire the event with the |init_data| as the request.
std::string message;
if (init_data && init_data_length) {
- message = std::string(reinterpret_cast<const char*>(init_data),
- init_data_length);
+ message =
+ std::string(reinterpret_cast<const char*>(init_data), init_data_length);
}
key_message_cb_.Run(session_id_string, message, std::string());
return true;
}
-void AesDecryptor::AddKey(const uint8* key,
- int key_length,
- const uint8* init_data,
- int init_data_length,
+void AesDecryptor::AddKey(const uint8* key, int key_length,
+ const uint8* init_data, int init_data_length,
const std::string& session_id) {
CHECK(key);
CHECK_GT(key_length, 0);
@@ -173,7 +167,7 @@ void AesDecryptor::AddKey(const uint8* key,
// TODO(xhwang): Fix the decryptor to accept no |init_data|. See
// http://crbug.com/123265. Until then, ensure a non-empty value is passed.
- static const uint8 kDummyInitData[1] = { 0 };
+ static const uint8 kDummyInitData[1] = {0};
if (!init_data) {
init_data = kDummyInitData;
init_data_length = arraysize(kDummyInitData);
@@ -183,7 +177,7 @@ void AesDecryptor::AddKey(const uint8* key,
// compliant later (http://crbug.com/123262, http://crbug.com/123265).
std::string key_id_string(reinterpret_cast<const char*>(init_data),
init_data_length);
- std::string key_string(reinterpret_cast<const char*>(key) , key_length);
+ std::string key_string(reinterpret_cast<const char*>(key), key_length);
scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string));
if (!decryption_key) {
DVLOG(1) << "Could not create key.";
@@ -199,21 +193,16 @@ void AesDecryptor::AddKey(const uint8* key,
SetKey(key_id_string, decryption_key.Pass());
- if (!new_audio_key_cb_.is_null())
- new_audio_key_cb_.Run();
+ if (!new_audio_key_cb_.is_null()) new_audio_key_cb_.Run();
- if (!new_video_key_cb_.is_null())
- new_video_key_cb_.Run();
+ if (!new_video_key_cb_.is_null()) new_video_key_cb_.Run();
key_added_cb_.Run(session_id);
}
-void AesDecryptor::CancelKeyRequest(const std::string& session_id) {
-}
+void AesDecryptor::CancelKeyRequest(const std::string& session_id) {}
-Decryptor* AesDecryptor::GetDecryptor() {
- return this;
-}
+Decryptor* AesDecryptor::GetDecryptor() { return this; }
void AesDecryptor::RegisterNewKeyCB(StreamType stream_type,
const NewKeyCB& new_key_cb) {
@@ -232,16 +221,17 @@ void AesDecryptor::RegisterNewKeyCB(StreamType stream_type,
void AesDecryptor::Decrypt(StreamType stream_type,
const scoped_refptr<DecoderBuffer>& encrypted,
const DecryptCB& decrypt_cb) {
- CHECK(encrypted->GetDecryptConfig());
+ CHECK(encrypted->get_decrypt_config());
scoped_refptr<DecoderBuffer> decrypted;
// An empty iv string signals that the frame is unencrypted.
- if (encrypted->GetDecryptConfig()->iv().empty()) {
- int data_offset = encrypted->GetDecryptConfig()->data_offset();
- decrypted = DecoderBuffer::CopyFrom(encrypted->GetData() + data_offset,
- encrypted->GetDataSize() - data_offset);
+ if (encrypted->get_decrypt_config()->iv().empty()) {
+ int data_offset = encrypted->get_decrypt_config()->data_offset();
+ decrypted =
+ DecoderBuffer::copy_from(encrypted->get_data() + data_offset,
+ encrypted->get_data_size() - data_offset);
} else {
- const std::string& key_id = encrypted->GetDecryptConfig()->key_id();
+ const std::string& key_id = encrypted->get_decrypt_config()->key_id();
DecryptionKey* key = GetKey(key_id);
if (!key) {
DVLOG(1) << "Could not find a matching key for the given key ID.";
@@ -258,8 +248,8 @@ void AesDecryptor::Decrypt(StreamType stream_type,
}
}
- decrypted->SetTimestamp(encrypted->GetTimestamp());
- decrypted->SetDuration(encrypted->GetDuration());
+ decrypted->set_timestamp(encrypted->get_timestamp());
+ decrypted->set_duration(encrypted->get_duration());
decrypt_cb.Run(kSuccess, decrypted);
}
@@ -314,24 +304,21 @@ AesDecryptor::DecryptionKey* AesDecryptor::GetKey(
const std::string& key_id) const {
base::AutoLock auto_lock(key_map_lock_);
KeyMap::const_iterator found = key_map_.find(key_id);
- if (found == key_map_.end())
- return NULL;
+ if (found == key_map_.end()) return NULL;
return found->second;
}
AesDecryptor::DecryptionKey::DecryptionKey(const std::string& secret)
- : secret_(secret) {
-}
+ : secret_(secret) {}
AesDecryptor::DecryptionKey::~DecryptionKey() {}
bool AesDecryptor::DecryptionKey::Init() {
CHECK(!secret_.empty());
- decryption_key_.reset(crypto::SymmetricKey::Import(
- crypto::SymmetricKey::AES, secret_));
- if (!decryption_key_)
- return false;
+ decryption_key_.reset(
+ crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_));
+ if (!decryption_key_) return false;
return true;
}

Powered by Google App Engine
This is Rietveld 408576698