2013-09-24 01:35:40 +00:00
|
|
|
// Copyright (c) 2012 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_DECRYPT_CONFIG_H_
|
|
|
|
#define MEDIA_BASE_DECRYPT_CONFIG_H_
|
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/memory/scoped_ptr.h"
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-09-24 01:35:40 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// The Common Encryption spec provides for subsample encryption, where portions
|
|
|
|
/// of a sample are not encrypted. A SubsampleEntry specifies the number of
|
|
|
|
/// clear and encrypted bytes in each subsample. For decryption, all of the
|
|
|
|
/// encrypted bytes in a sample should be considered a single logical stream,
|
|
|
|
/// regardless of how they are divided into subsamples, and the clear bytes
|
|
|
|
/// should not be considered as part of decryption. This is logically equivalent
|
2014-08-25 22:51:19 +00:00
|
|
|
/// to concatenating all @a cipher_bytes portions of subsamples, decrypting that
|
2014-01-24 18:46:46 +00:00
|
|
|
/// result, and then copying each byte from the decrypted block over the
|
|
|
|
/// corresponding encrypted byte.
|
2013-09-24 01:35:40 +00:00
|
|
|
struct SubsampleEntry {
|
2014-09-30 21:52:21 +00:00
|
|
|
uint16_t clear_bytes;
|
|
|
|
uint32_t cipher_bytes;
|
2013-09-24 01:35:40 +00:00
|
|
|
};
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Contains all the information that a decryptor needs to decrypt a media
|
|
|
|
/// sample.
|
2013-09-24 04:17:12 +00:00
|
|
|
class DecryptConfig {
|
2013-09-24 01:35:40 +00:00
|
|
|
public:
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Keys are always 128 bits.
|
2013-11-27 02:23:30 +00:00
|
|
|
static const size_t kDecryptionKeySize = 16;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @param key_id is the ID that references the decryption key.
|
|
|
|
/// @param iv is the initialization vector defined by the encryptor.
|
|
|
|
/// @param data_offset is the amount of data that should be discarded from
|
|
|
|
/// the head of the sample buffer before applying subsample
|
|
|
|
/// information. A decrypted buffer will be shorter than an encrypted
|
|
|
|
/// buffer by this amount.
|
|
|
|
/// @param subsamples defines the clear and encrypted portions of the sample
|
|
|
|
/// as described in SubsampleEntry. A decrypted buffer will be equal
|
|
|
|
/// in size to the sum of the subsample sizes.
|
2014-09-30 21:52:21 +00:00
|
|
|
DecryptConfig(const std::vector<uint8_t>& key_id,
|
|
|
|
const std::vector<uint8_t>& iv,
|
2013-09-24 01:35:40 +00:00
|
|
|
const int data_offset,
|
|
|
|
const std::vector<SubsampleEntry>& subsamples);
|
|
|
|
~DecryptConfig();
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
const std::vector<uint8_t>& key_id() const { return key_id_; }
|
|
|
|
const std::vector<uint8_t>& iv() const { return iv_; }
|
2013-09-24 01:35:40 +00:00
|
|
|
int data_offset() const { return data_offset_; }
|
|
|
|
const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; }
|
|
|
|
|
|
|
|
private:
|
2014-09-30 21:52:21 +00:00
|
|
|
const std::vector<uint8_t> key_id_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
// Initialization vector.
|
2014-09-30 21:52:21 +00:00
|
|
|
const std::vector<uint8_t> iv_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
// Amount of data to be discarded before applying subsample information.
|
|
|
|
const int data_offset_;
|
|
|
|
|
|
|
|
// Subsample information. May be empty for some formats, meaning entire frame
|
|
|
|
// (less data ignored by data_offset_) is encrypted.
|
|
|
|
const std::vector<SubsampleEntry> subsamples_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(DecryptConfig);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_BASE_DECRYPT_CONFIG_H_
|