OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_BASE_DECRYPTOR_H_ |
| 6 #define MEDIA_BASE_DECRYPTOR_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 #include "media/base/media_export.h" |
| 14 |
| 15 namespace crypto { |
| 16 class SymmetricKey; |
| 17 } |
| 18 |
| 19 namespace media { |
| 20 |
| 21 class DecoderBuffer; |
| 22 |
| 23 // Interface for decrypting frames. |
| 24 class MEDIA_EXPORT Decryptor { |
| 25 public: |
| 26 Decryptor(); |
| 27 virtual ~Decryptor(); |
| 28 |
| 29 // Add a |key_id| and |key| pair to the key system. The key is not limited to |
| 30 // a decryption key. It can be any data that the key system accepts, such as |
| 31 // a license. If multiple calls of this function set different keys for the |
| 32 // same |key_id|, the older key will be replaced by the newer key. |
| 33 virtual void AddKey(const uint8* key_id, int key_id_size, |
| 34 const uint8* key, int key_size) = 0; |
| 35 |
| 36 // Decrypt |input| buffer. The |input| should not be NULL. |
| 37 // Return a DecoderBuffer with the decrypted data if decryption succeeded. |
| 38 // Return NULL if decryption failed. |
| 39 virtual scoped_refptr<DecoderBuffer> Decrypt( |
| 40 const scoped_refptr<DecoderBuffer>& input) = 0; |
| 41 |
| 42 // Decrypt |input| using |key|. |offset| is the number of bytes into |input| |
| 43 // the encrypted data is. |
| 44 // Return a DecoderBuffer with the decrypted data if decryption succeeded. |
| 45 // Return NULL if decryption failed. |
| 46 static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, |
| 47 crypto::SymmetricKey* key, |
| 48 int offset); |
| 49 |
| 50 // Generates a 16 byte CTR counter block. The format is |
| 51 // | iv | block counter |. |iv| is an 8 byte CTR IV. Returns counter block on |
| 52 // success. Returns empth string on failure. |
| 53 static std::string GenerateCounterBlock(uint64 iv); |
| 54 |
| 55 protected: |
| 56 base::Lock lock_; |
| 57 |
| 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(Decryptor); |
| 60 }; |
| 61 |
| 62 } // namespace media |
| 63 |
| 64 #endif // MEDIA_BASE_DECRYPTOR_H_ |
OLD | NEW |