tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ClearKeySession.cpp (2338B)


      1 /*
      2 * Copyright 2015, Mozilla Foundation and contributors
      3 *
      4 * Licensed under the Apache License, Version 2.0 (the "License");
      5 * you may not use this file except in compliance with the License.
      6 * You may obtain a copy of the License at
      7 *
      8 * http://www.apache.org/licenses/LICENSE-2.0
      9 *
     10 * Unless required by applicable law or agreed to in writing, software
     11 * distributed under the License is distributed on an "AS IS" BASIS,
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 * See the License for the specific language governing permissions and
     14 * limitations under the License.
     15 */
     16 
     17 #include "ClearKeySession.h"
     18 
     19 #include <assert.h>
     20 #include <string.h>
     21 
     22 #include "BigEndian.h"
     23 #include "ClearKeyDecryptionManager.h"
     24 #include "ClearKeyStorage.h"
     25 #include "ClearKeyUtils.h"
     26 #include "psshparser/PsshParser.h"
     27 
     28 using namespace mozilla;
     29 using namespace cdm;
     30 
     31 ClearKeySession::ClearKeySession(const std::string& aSessionId,
     32                                 SessionType aSessionType)
     33    : mSessionId(aSessionId), mSessionType(aSessionType) {
     34  CK_LOGD("ClearKeySession ctor %p", this);
     35 }
     36 
     37 ClearKeySession::~ClearKeySession() {
     38  CK_LOGD("ClearKeySession dtor %p", this);
     39 }
     40 
     41 bool ClearKeySession::Init(InitDataType aInitDataType, const uint8_t* aInitData,
     42                           uint32_t aInitDataSize) {
     43  CK_LOGD("ClearKeySession::Init");
     44 
     45  if (aInitDataType == InitDataType::kCenc) {
     46    ParseCENCInitData(aInitData, aInitDataSize, mKeyIds);
     47  } else if (aInitDataType == InitDataType::kKeyIds) {
     48    ClearKeyUtils::ParseKeyIdsInitData(aInitData, aInitDataSize, mKeyIds);
     49  } else if (aInitDataType == InitDataType::kWebM &&
     50             aInitDataSize <= kMaxWebmInitDataSize) {
     51    // "webm" initData format is simply the raw bytes of the keyId.
     52    std::vector<uint8_t> keyId;
     53    keyId.assign(aInitData, aInitData + aInitDataSize);
     54    mKeyIds.push_back(keyId);
     55  }
     56 
     57  if (mKeyIds.empty()) {
     58    CK_LOGD("ClearKeySession::Init, failed to get keyId");
     59    return false;
     60  }
     61 #ifdef WMF_CLEARKEY_DEBUG
     62  for (const auto& keyId : mKeyIds) {
     63    CK_LOGARRAY("ClearKeySession::Init, KeyId : ", keyId.data(), keyId.size());
     64  }
     65 #endif
     66  return true;
     67 }
     68 
     69 SessionType ClearKeySession::Type() const { return mSessionType; }
     70 
     71 void ClearKeySession::AddKeyId(const KeyId& aKeyId) {
     72  mKeyIds.push_back(aKeyId);
     73 }