OLD | NEW |
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 "media/cdm/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <list> | 8 #include <list> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/stl_util.h" | |
15 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
16 #include "crypto/encryptor.h" | 15 #include "crypto/encryptor.h" |
17 #include "crypto/symmetric_key.h" | 16 #include "crypto/symmetric_key.h" |
18 #include "media/base/audio_decoder_config.h" | 17 #include "media/base/audio_decoder_config.h" |
19 #include "media/base/cdm_key_information.h" | 18 #include "media/base/cdm_key_information.h" |
20 #include "media/base/cdm_promise.h" | 19 #include "media/base/cdm_promise.h" |
21 #include "media/base/decoder_buffer.h" | 20 #include "media/base/decoder_buffer.h" |
22 #include "media/base/decrypt_config.h" | 21 #include "media/base/decrypt_config.h" |
23 #include "media/base/limits.h" | 22 #include "media/base/limits.h" |
24 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
25 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
26 #include "media/cdm/json_web_key.h" | 25 #include "media/cdm/json_web_key.h" |
27 | 26 |
28 #if defined(USE_PROPRIETARY_CODECS) | 27 #if defined(USE_PROPRIETARY_CODECS) |
29 #include "media/cdm/cenc_utils.h" | 28 #include "media/cdm/cenc_utils.h" |
30 #endif | 29 #endif |
31 | 30 |
32 namespace media { | 31 namespace media { |
33 | 32 |
34 // Keeps track of the session IDs and DecryptionKeys. The keys are ordered by | 33 // Keeps track of the session IDs and DecryptionKeys. The keys are ordered by |
35 // insertion time (last insertion is first). It takes ownership of the | 34 // insertion time (last insertion is first). It takes ownership of the |
36 // DecryptionKeys. | 35 // DecryptionKeys. |
37 class AesDecryptor::SessionIdDecryptionKeyMap { | 36 class AesDecryptor::SessionIdDecryptionKeyMap { |
38 // Use a std::list to actually hold the data. Insertion is always done | 37 // Use a std::list to actually hold the data. Insertion is always done |
39 // at the front, so the "latest" decryption key is always the first one | 38 // at the front, so the "latest" decryption key is always the first one |
40 // in the list. | 39 // in the list. |
41 typedef std::list<std::pair<std::string, DecryptionKey*> > KeyList; | 40 using KeyList = |
| 41 std::list<std::pair<std::string, std::unique_ptr<DecryptionKey>>>; |
42 | 42 |
43 public: | 43 public: |
44 SessionIdDecryptionKeyMap() {} | 44 SessionIdDecryptionKeyMap() {} |
45 ~SessionIdDecryptionKeyMap() { base::STLDeleteValues(&key_list_); } | 45 ~SessionIdDecryptionKeyMap() {} |
46 | 46 |
47 // Replaces value if |session_id| is already present, or adds it if not. | 47 // Replaces value if |session_id| is already present, or adds it if not. |
48 // This |decryption_key| becomes the latest until another insertion or | 48 // This |decryption_key| becomes the latest until another insertion or |
49 // |session_id| is erased. | 49 // |session_id| is erased. |
50 void Insert(const std::string& session_id, | 50 void Insert(const std::string& session_id, |
51 std::unique_ptr<DecryptionKey> decryption_key); | 51 std::unique_ptr<DecryptionKey> decryption_key); |
52 | 52 |
53 // Deletes the entry for |session_id| if present. | 53 // Deletes the entry for |session_id| if present. |
54 void Erase(const std::string& session_id); | 54 void Erase(const std::string& session_id); |
55 | 55 |
56 // Returns whether the list is empty | 56 // Returns whether the list is empty |
57 bool Empty() const { return key_list_.empty(); } | 57 bool Empty() const { return key_list_.empty(); } |
58 | 58 |
59 // Returns the last inserted DecryptionKey. | 59 // Returns the last inserted DecryptionKey. |
60 DecryptionKey* LatestDecryptionKey() { | 60 DecryptionKey* LatestDecryptionKey() { |
61 DCHECK(!key_list_.empty()); | 61 DCHECK(!key_list_.empty()); |
62 return key_list_.begin()->second; | 62 return key_list_.begin()->second.get(); |
63 } | 63 } |
64 | 64 |
65 bool Contains(const std::string& session_id) { | 65 bool Contains(const std::string& session_id) { |
66 return Find(session_id) != key_list_.end(); | 66 return Find(session_id) != key_list_.end(); |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 // Searches the list for an element with |session_id|. | 70 // Searches the list for an element with |session_id|. |
71 KeyList::iterator Find(const std::string& session_id); | 71 KeyList::iterator Find(const std::string& session_id); |
72 | 72 |
73 // Deletes the entry pointed to by |position|. | 73 // Deletes the entry pointed to by |position|. |
74 void Erase(KeyList::iterator position); | 74 void Erase(KeyList::iterator position); |
75 | 75 |
76 KeyList key_list_; | 76 KeyList key_list_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(SessionIdDecryptionKeyMap); | 78 DISALLOW_COPY_AND_ASSIGN(SessionIdDecryptionKeyMap); |
79 }; | 79 }; |
80 | 80 |
81 void AesDecryptor::SessionIdDecryptionKeyMap::Insert( | 81 void AesDecryptor::SessionIdDecryptionKeyMap::Insert( |
82 const std::string& session_id, | 82 const std::string& session_id, |
83 std::unique_ptr<DecryptionKey> decryption_key) { | 83 std::unique_ptr<DecryptionKey> decryption_key) { |
84 KeyList::iterator it = Find(session_id); | 84 KeyList::iterator it = Find(session_id); |
85 if (it != key_list_.end()) | 85 if (it != key_list_.end()) |
86 Erase(it); | 86 Erase(it); |
87 DecryptionKey* raw_ptr = decryption_key.release(); | 87 key_list_.push_front(std::make_pair(session_id, std::move(decryption_key))); |
88 key_list_.push_front(std::make_pair(session_id, raw_ptr)); | |
89 } | 88 } |
90 | 89 |
91 void AesDecryptor::SessionIdDecryptionKeyMap::Erase( | 90 void AesDecryptor::SessionIdDecryptionKeyMap::Erase( |
92 const std::string& session_id) { | 91 const std::string& session_id) { |
93 KeyList::iterator it = Find(session_id); | 92 KeyList::iterator it = Find(session_id); |
94 if (it == key_list_.end()) | 93 if (it == key_list_.end()) |
95 return; | 94 return; |
96 Erase(it); | 95 Erase(it); |
97 } | 96 } |
98 | 97 |
99 AesDecryptor::SessionIdDecryptionKeyMap::KeyList::iterator | 98 AesDecryptor::SessionIdDecryptionKeyMap::KeyList::iterator |
100 AesDecryptor::SessionIdDecryptionKeyMap::Find(const std::string& session_id) { | 99 AesDecryptor::SessionIdDecryptionKeyMap::Find(const std::string& session_id) { |
101 for (KeyList::iterator it = key_list_.begin(); it != key_list_.end(); ++it) { | 100 for (KeyList::iterator it = key_list_.begin(); it != key_list_.end(); ++it) { |
102 if (it->first == session_id) | 101 if (it->first == session_id) |
103 return it; | 102 return it; |
104 } | 103 } |
105 return key_list_.end(); | 104 return key_list_.end(); |
106 } | 105 } |
107 | 106 |
108 void AesDecryptor::SessionIdDecryptionKeyMap::Erase( | 107 void AesDecryptor::SessionIdDecryptionKeyMap::Erase( |
109 KeyList::iterator position) { | 108 KeyList::iterator position) { |
110 DCHECK(position->second); | 109 DCHECK(position->second); |
111 delete position->second; | |
112 key_list_.erase(position); | 110 key_list_.erase(position); |
113 } | 111 } |
114 | 112 |
115 uint32_t AesDecryptor::next_session_id_ = 1; | 113 uint32_t AesDecryptor::next_session_id_ = 1; |
116 | 114 |
117 enum ClearBytesBufferSel { | 115 enum ClearBytesBufferSel { |
118 kSrcContainsClearBytes, | 116 kSrcContainsClearBytes, |
119 kDstContainsClearBytes | 117 kDstContainsClearBytes |
120 }; | 118 }; |
121 | 119 |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 bool AesDecryptor::DecryptionKey::Init() { | 597 bool AesDecryptor::DecryptionKey::Init() { |
600 CHECK(!secret_.empty()); | 598 CHECK(!secret_.empty()); |
601 decryption_key_ = | 599 decryption_key_ = |
602 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_); | 600 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_); |
603 if (!decryption_key_) | 601 if (!decryption_key_) |
604 return false; | 602 return false; |
605 return true; | 603 return true; |
606 } | 604 } |
607 | 605 |
608 } // namespace media | 606 } // namespace media |
OLD | NEW |