Chromium Code Reviews| Index: media/base/encryption_scheme.h |
| diff --git a/media/base/encryption_scheme.h b/media/base/encryption_scheme.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..31a83e2d1af65674165cfdac0522274e337d89e3 |
| --- /dev/null |
| +++ b/media/base/encryption_scheme.h |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_BASE_ENCRYPTION_SCHEME_H_ |
| +#define MEDIA_BASE_ENCRYPTION_SCHEME_H_ |
| + |
| +#include <stdint.h> |
| + |
| +namespace media { |
| + |
| +// Specification of whether and how the stream is encrypted (in whole or part). |
| +class EncryptionScheme { |
| + public: |
| + // Algorithm and mode used for encryption. |
| + enum CipherMode { |
| + kCipherModeNone, |
| + kCipherModeAesCtr, |
| + kCipherModeAesCbc, |
| + kCipherModeMax = kCipherModeAesCbc |
| + }; |
| + |
| + // V3 of the CENC standard adds pattern encryption, through two new |
| + // protection schemes 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC). |
| + // The pattern applies only to the 'encrypted' part of the frame (as |
| + // defined by the relevant subsample entries), and reduces further the |
| + // actual encryption applied through a repeating pattern of (encrypt:skip) |
| + // 16 byte blocks. For example, in a (1:9) pattern, the first block is |
| + // encrypted, and the next nine are skipped. This pattern is applied |
| + // repeatedly until the end of the last 16-byte block in the subsample. |
| + // Any remaining bytes are left clear. |
| + // If either or both of encrypt_blocks or skip_blocks is 0, pattern |
| + // encryption is disabled. |
| + class PatternSpec { |
| + public: |
| + PatternSpec(); |
| + PatternSpec(uint32_t encrypt_blocks, uint32_t skip_blocks); |
| + ~PatternSpec(); |
| + |
| + bool Matches(const PatternSpec& other) const; |
| + |
| + uint32_t encrypt_blocks() const { return encrypt_blocks_; } |
| + uint32_t skip_blocks() const { return skip_blocks_; } |
| + |
| + bool IsInEffect() const; |
| + |
| + private: |
| + uint32_t encrypt_blocks_; |
| + uint32_t skip_blocks_; |
| + |
| + // Allow copy and assignment. |
| + }; |
| + |
| + EncryptionScheme(); |
| + explicit EncryptionScheme(bool is_encrypted); |
|
halliwell
2016/01/13 03:29:42
As mentioned in downstream CLs, I don't like calls
dougsteed
2016/02/09 22:58:54
Following our discussion, I added a static functio
|
| + explicit EncryptionScheme(CipherMode mode); |
| + EncryptionScheme(CipherMode mode, const PatternSpec& pattern); |
| + ~EncryptionScheme(); |
| + |
| + void Initialize(CipherMode mode, const PatternSpec& pattern); |
| + bool Matches(const EncryptionScheme& other) const; |
| + |
| + bool is_encrypted() const; |
| + CipherMode mode() const { return mode_; } |
| + const PatternSpec& pattern() const { return pattern_; } |
| + |
| + private: |
| + CipherMode mode_; |
| + PatternSpec pattern_; |
| + |
| + // Allow copy and assignment. |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_ENCRYPTION_SCHEME_H_ |