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" | 13 #include "base/synchronization/lock.h" |
14 #include "media/base/media_export.h" | 14 #include "media/base/media_export.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 class DecryptorClient; | |
23 | 24 |
24 // Decrypts AES encrypted buffer into unencrypted buffer. | 25 // Decrypts AES encrypted buffer into unencrypted buffer. |
25 class MEDIA_EXPORT AesDecryptor { | 26 class MEDIA_EXPORT AesDecryptor { |
26 public: | 27 public: |
28 enum KeyError { | |
29 UnknownError = 1, | |
scherkus (not reviewing)
2012/06/12 03:15:58
these all get k prefix
xhwang
2012/06/12 19:01:15
Done.
| |
30 ClientError, | |
31 ServiceError, | |
32 OutputError, | |
33 HardwareChangeError, | |
34 DomainError | |
35 }; | |
36 | |
27 AesDecryptor(); | 37 AesDecryptor(); |
28 ~AesDecryptor(); | 38 ~AesDecryptor(); |
29 | 39 |
30 // Add a |key_id| and |key| pair to the key system. The key is not limited to | 40 // The AesDecryptor does not take ownership of the |client|. The |client| |
31 // a decryption key. It can be any data that the key system accepts, such as | 41 // must be valid throughout the lifeime of the AesDecryptor. |
ddorwin
2012/06/11 21:02:40
lifetime
xhwang
2012/06/12 19:01:15
Done.
| |
32 // a license. If multiple calls of this function set different keys for the | 42 void Init(DecryptorClient* client); |
scherkus (not reviewing)
2012/06/12 03:15:58
why not pass into ctor?
I know you eventually wan
xhwang
2012/06/12 19:01:15
Done. It actually make the code much cleaner. Than
| |
33 // 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 const uint8* key, int key_size); | |
36 | 43 |
37 // Decrypt |input| buffer. The |input| should not be NULL. | 44 // Generates a key request. The result of this call will be reported via the |
38 // Return a DecoderBuffer with the decrypted data if decryption succeeded. | 45 // client's KeyMessage or KeyError methods. |
scherkus (not reviewing)
2012/06/12 03:15:58
suffix fn names with () in docs here + below
xhwang
2012/06/12 19:01:15
Done.
| |
39 // Return NULL if decryption failed. | 46 void GenerateKeyRequest(const std::string& key_system, |
47 const uint8* init_data, | |
48 int init_data_length); | |
49 | |
50 // Adds a |key| to the key system. The key is not limited to a decryption key. | |
51 // It can be any data that the key system accepts, such as a license. | |
52 // If multiple calls of this function set different keys for the same | |
53 // |key_id|, the older key will be replaced by the newer key. | |
54 // The result of this call will be reported via the client's KeyAdded, | |
55 // KeyMessage or KeyError methods. | |
56 void AddKey(const std::string& key_system, | |
57 const uint8* key, | |
58 int key_length, | |
59 const uint8* init_data, | |
60 int init_data_length, | |
61 const std::string& session_id); | |
62 | |
63 void CancelKeyRequest(const std::string& key_system, | |
ddorwin
2012/06/11 21:02:40
// Cancels the key request specified by |session_i
xhwang
2012/06/12 19:01:15
Done.
| |
64 const std::string& session_id); | |
65 | |
66 // Decrypts the |input| buffer, which should not be NULL. | |
67 // Returns a DecoderBuffer with the decrypted data if decryption succeeded. | |
68 // Returns NULL if decryption failed. | |
40 scoped_refptr<DecoderBuffer> Decrypt( | 69 scoped_refptr<DecoderBuffer> Decrypt( |
41 const scoped_refptr<DecoderBuffer>& input); | 70 const scoped_refptr<DecoderBuffer>& input); |
42 | 71 |
43 private: | 72 private: |
44 // KeyMap owns the crypto::SymmetricKey* and must delete them when they are | 73 // KeyMap owns the crypto::SymmetricKey* and must delete them when they are |
45 // not needed any more. | 74 // not needed any more. |
46 typedef base::hash_map<std::string, crypto::SymmetricKey*> KeyMap; | 75 typedef base::hash_map<std::string, crypto::SymmetricKey*> KeyMap; |
47 KeyMap key_map_; | 76 KeyMap key_map_; // Protected by the |lock_|. |
48 base::Lock lock_; | 77 base::Lock lock_; // Protects the |key_map_|. |
ddorwin
2012/06/11 21:02:40
if it is specific to the key_map_, you might name
xhwang
2012/06/12 19:01:15
Done.
| |
78 | |
79 DecryptorClient* client_; | |
80 | |
81 uint32_t session_id_; | |
ddorwin
2012/06/11 21:02:40
last_session_id_ or session_id_incrementer_
scherkus (not reviewing)
2012/06/12 03:15:58
I like "next_session_id_" then inside the .cc conv
xhwang
2012/06/12 19:01:15
Done.
xhwang
2012/06/12 19:01:15
Done.
| |
49 | 82 |
50 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); | 83 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); |
51 }; | 84 }; |
52 | 85 |
53 } // namespace media | 86 } // namespace media |
54 | 87 |
55 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 88 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
OLD | NEW |