2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-11 21:44:55 +00:00
|
|
|
//
|
|
|
|
// EncryptorSource is responsible for encryption key acquisition.
|
|
|
|
|
|
|
|
#ifndef MEDIA_BASE_ENCRYPTOR_SOURCE_H_
|
|
|
|
#define MEDIA_BASE_ENCRYPTOR_SOURCE_H_
|
|
|
|
|
2013-11-12 20:34:58 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
#include "base/memory/scoped_ptr.h"
|
2013-11-12 20:34:58 +00:00
|
|
|
#include "media/base/aes_encryptor.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
#include "media/base/status.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
2014-01-13 19:34:08 +00:00
|
|
|
class AesCtrEncryptor;
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
class EncryptorSource {
|
|
|
|
public:
|
2013-11-12 20:34:58 +00:00
|
|
|
EncryptorSource();
|
|
|
|
virtual ~EncryptorSource();
|
|
|
|
|
2014-01-13 19:34:08 +00:00
|
|
|
// Initialize the encryptor source. Calling other public methods of this
|
|
|
|
// class without this method returning Status::OK, results in an undefined
|
|
|
|
// behavior.
|
2013-11-12 20:34:58 +00:00
|
|
|
virtual Status Initialize() = 0;
|
|
|
|
|
2014-01-13 19:34:08 +00:00
|
|
|
// Refresh the encryptor. NOP except for key rotation encryptor source.
|
2014-03-19 00:09:50 +00:00
|
|
|
// TODO: Do we need to pass in duration or fragment number?
|
2013-11-12 20:34:58 +00:00
|
|
|
virtual void RefreshEncryptor() {}
|
|
|
|
|
2014-01-13 19:34:08 +00:00
|
|
|
// Create an encryptor from this encryptor source. The encryptor will be
|
|
|
|
// initialized with a random IV of the default size by default. The behavior
|
|
|
|
// can be adjusted using set_iv_size or set_iv (exclusive).
|
|
|
|
scoped_ptr<AesCtrEncryptor> CreateEncryptor();
|
|
|
|
|
2013-11-12 20:34:58 +00:00
|
|
|
const std::vector<uint8>& key_id() const { return key_id_; }
|
|
|
|
const std::vector<uint8>& key() const { return key_; }
|
|
|
|
const std::vector<uint8>& pssh() const { return pssh_; }
|
|
|
|
const std::vector<uint8>& key_system_id() const { return key_system_id_; }
|
2014-01-13 19:34:08 +00:00
|
|
|
size_t iv_size() const { return iv_.empty() ? iv_size_ : iv_.size(); }
|
|
|
|
|
|
|
|
// Set IV size. The encryptor will be initialized with a random IV of the
|
|
|
|
// specified size. Mutally exclusive with set_iv.
|
|
|
|
void set_iv_size(size_t iv_size) { iv_size_ = iv_size; }
|
|
|
|
// Set IV. The encryptor will be initialized with the specified IV.
|
|
|
|
// Mutally exclusive with set_iv_size.
|
|
|
|
void set_iv(std::vector<uint8>& iv) { iv_ = iv; }
|
2013-11-12 20:34:58 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void set_key_id(const std::vector<uint8>& key_id) { key_id_ = key_id; }
|
|
|
|
void set_key(const std::vector<uint8>& key) { key_ = key; }
|
|
|
|
void set_pssh(const std::vector<uint8>& pssh) { pssh_ = pssh; }
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
private:
|
2013-11-12 20:34:58 +00:00
|
|
|
std::vector<uint8> key_id_;
|
|
|
|
std::vector<uint8> key_;
|
|
|
|
std::vector<uint8> pssh_;
|
2014-01-13 19:34:08 +00:00
|
|
|
size_t iv_size_;
|
|
|
|
std::vector<uint8> iv_;
|
2013-11-12 20:34:58 +00:00
|
|
|
const std::vector<uint8> key_system_id_;
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(EncryptorSource);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MEDIA_BASE_ENCRYPTOR_SOURCE_H_
|