| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 5 #ifndef MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
| 6 #define MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 6 #define MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
| 14 #include "media/crypto/decryptor.h" |
| 15 | 15 |
| 16 namespace crypto { | 16 namespace crypto { |
| 17 class SymmetricKey; | 17 class SymmetricKey; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 class DecoderBuffer; | 22 class DecoderBuffer; |
| 23 | 23 |
| 24 // Decrypts AES encrypted buffer into unencrypted buffer. | 24 // Decrypts AES encrypted buffer into unencrypted buffer. |
| 25 class MEDIA_EXPORT AesDecryptor { | 25 class MEDIA_EXPORT AesDecryptor : public Decryptor { |
| 26 public: | 26 public: |
| 27 AesDecryptor(); | 27 AesDecryptor(); |
| 28 ~AesDecryptor(); | 28 virtual ~AesDecryptor(); |
| 29 | 29 |
| 30 // Decryptor implementation. |
| 30 // Add a |key_id| and |key| pair to the key system. The key is not limited to | 31 // Add a |key_id| and |key| pair to the key system. The key is not limited to |
| 31 // a decryption key. It can be any data that the key system accepts, such as | 32 // a decryption key. It can be any data that the key system accepts, such as |
| 32 // a license. If multiple calls of this function set different keys for the | 33 // a license. If multiple calls of this function set different keys for the |
| 33 // same |key_id|, the older key will be replaced by the newer key. | 34 // same |key_id|, the older key will be replaced by the newer key. |
| 34 void AddKey(const uint8* key_id, int key_id_size, | 35 virtual void AddKey(const uint8* key_id, int key_id_size, |
| 35 const uint8* key, int key_size); | 36 const uint8* key, int key_size) OVERRIDE; |
| 36 | 37 |
| 37 // Decrypt |input| buffer. The |input| should not be NULL. | 38 // Decrypt |input| buffer. The |input| should not be NULL. |
| 38 // Return a DecoderBuffer with the decrypted data if decryption succeeded. | 39 // Return a DecoderBuffer with the decrypted data if decryption succeeded. |
| 39 // Return NULL if decryption failed. | 40 // Return NULL if decryption failed. |
| 40 scoped_refptr<DecoderBuffer> Decrypt( | 41 virtual scoped_refptr<DecoderBuffer> Decrypt( |
| 41 const scoped_refptr<DecoderBuffer>& input); | 42 const scoped_refptr<DecoderBuffer>& input) OVERRIDE; |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 // KeyMap owns the crypto::SymmetricKey* and must delete them when they are | 45 // KeyMap owns the crypto::SymmetricKey* and must delete them when they are |
| 45 // not needed any more. | 46 // not needed any more. |
| 46 typedef base::hash_map<std::string, crypto::SymmetricKey*> KeyMap; | 47 typedef base::hash_map<std::string, crypto::SymmetricKey*> KeyMap; |
| 47 KeyMap key_map_; | 48 KeyMap key_map_; |
| 48 base::Lock lock_; | |
| 49 | 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); | 50 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 } // namespace media | 53 } // namespace media |
| 54 | 54 |
| 55 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 55 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
| OLD | NEW |