summaryrefslogtreecommitdiff
path: root/test/vp8_decrypt_test.cc
blob: ea7b92049900149324bf1337cc6eebb9dd5fd8a3 (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
57
58
59
60
61
62
63
64
65
/*
 *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <cstdio>
#include <cstdlib>
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/decode_test_driver.h"
#include "test/ivf_video_source.h"

#if CONFIG_DECRYPT

namespace {

const uint8_t decrypt_key[32] = {
  255, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
};

}  // namespace

namespace libvpx_test {

TEST(TestDecrypt, NullKey) {
  vpx_codec_dec_cfg_t cfg = {0};
  vpx_codec_ctx_t decoder = {0};
  vpx_codec_err_t res = vpx_codec_dec_init(&decoder, &vpx_codec_vp8_dx_algo,
                                           &cfg, 0);
  ASSERT_EQ(VPX_CODEC_OK, res);

  res = vpx_codec_control(&decoder, VP8_SET_DECRYPT_KEY, NULL);
  ASSERT_EQ(VPX_CODEC_INVALID_PARAM, res);
}

TEST(TestDecrypt, DecryptWorks) {
  libvpx_test::IVFVideoSource video("vp80-00-comprehensive-001.ivf");
  video.Init();

  vpx_codec_dec_cfg_t dec_cfg = {0};
  Decoder decoder(dec_cfg, 0);

  // Zero decrypt key (by default)
  video.Begin();
  vpx_codec_err_t res = decoder.DecodeFrame(video.cxdata(), video.frame_size());
  ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();

  // Non-zero decrypt key
  video.Next();
  decoder.Control(VP8_SET_DECRYPT_KEY, decrypt_key);
  res = decoder.DecodeFrame(video.cxdata(), video.frame_size());
  ASSERT_NE(VPX_CODEC_OK, res) << decoder.DecodeError();
}

}  // namespace libvpx_test

#endif  // CONFIG_DECRYPT