summaryrefslogtreecommitdiffstats
path: root/media/cast/common/transport_encryption_handler.h
blob: 4dfa884a5c0f7d0976628536be16633f312b47ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2014 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_CAST_COMMON_TRANSPORT_ENCRYPTION_HANDLER_H_
#define MEDIA_CAST_COMMON_TRANSPORT_ENCRYPTION_HANDLER_H_

// Helper class to handle encryption for the Cast Transport library.

#include <stdint.h>

#include <string>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_piece.h"
#include "base/threading/non_thread_safe.h"

namespace crypto {
class Encryptor;
class SymmetricKey;
}

namespace media {
namespace cast {

class TransportEncryptionHandler : public base::NonThreadSafe {
 public:
  TransportEncryptionHandler();
  ~TransportEncryptionHandler();

  bool Initialize(const std::string& aes_key, const std::string& aes_iv_mask);

  bool Encrypt(uint32_t frame_id,
               const base::StringPiece& data,
               std::string* encrypted_data);

  bool Decrypt(uint32_t frame_id,
               const base::StringPiece& ciphertext,
               std::string* plaintext);

  bool is_activated() const { return is_activated_; }

 private:
  scoped_ptr<crypto::SymmetricKey> key_;
  scoped_ptr<crypto::Encryptor> encryptor_;
  std::string iv_mask_;
  bool is_activated_;

  DISALLOW_COPY_AND_ASSIGN(TransportEncryptionHandler);
};

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_COMMON_TRANSPORT_ENCRYPTION_HANDLER_H_