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
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80

media / base / cdm_key_information.cc [blame]

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "media/base/cdm_key_information.h"

#include <ostream>

#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"

namespace media {

CdmKeyInformation::CdmKeyInformation()
    : status(INTERNAL_ERROR), system_code(0) {}

CdmKeyInformation::CdmKeyInformation(const std::vector<uint8_t>& key_id,
                                     KeyStatus status,
                                     uint32_t system_code)
    : key_id(key_id), status(status), system_code(system_code) {}

CdmKeyInformation::CdmKeyInformation(const std::string& key_id,
                                     KeyStatus status,
                                     uint32_t system_code)
    : CdmKeyInformation(reinterpret_cast<const uint8_t*>(key_id.data()),
                        key_id.size(),
                        status,
                        system_code) {}

CdmKeyInformation::CdmKeyInformation(const uint8_t* key_id_data,
                                     size_t key_id_length,
                                     KeyStatus status,
                                     uint32_t system_code)
    : key_id(key_id_data, key_id_data + key_id_length),
      status(status),
      system_code(system_code) {}

CdmKeyInformation::CdmKeyInformation(const CdmKeyInformation& other) = default;

CdmKeyInformation::~CdmKeyInformation() = default;

// static
std::string CdmKeyInformation::KeyStatusToString(KeyStatus key_status) {
  switch (key_status) {
    case USABLE:
      return "USABLE";
    case INTERNAL_ERROR:
      return "INTERNAL_ERROR";
    case EXPIRED:
      return "EXPIRED";
    case OUTPUT_RESTRICTED:
      return "OUTPUT_RESTRICTED";
    case OUTPUT_DOWNSCALED:
      return "OUTPUT_DOWNSCALED";
    case KEY_STATUS_PENDING:
      return "KEY_STATUS_PENDING";
    case RELEASED:
      return "RELEASED";
  }

  NOTREACHED();
}

std::ostream& operator<<(std::ostream& os,
                         CdmKeyInformation::KeyStatus status) {
  return os << CdmKeyInformation::KeyStatusToString(status);
}

std::ostream& operator<<(std::ostream& os, const CdmKeyInformation& info) {
  return os << "key_id = " << base::HexEncode(info.key_id)
            << ", status = " << info.status
            << ", system_code = " << info.system_code;
}

}  // namespace media