1 /* 2 * Copyright (C) 2021 The Android Open Source Project 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 #pragma once 17 18 #include <utils/Mutex.h> 19 #include <utils/RefBase.h> 20 21 #include <cstdint> 22 #include <vector> 23 24 #include "ClearKeyTypes.h" 25 26 namespace clearkeydrm { 27 28 class Session : public ::android::RefBase { 29 public: Session(const std::vector<uint8_t> & sessionId)30 explicit Session(const std::vector<uint8_t>& sessionId) 31 : mSessionId(sessionId), mMockError(clearkeydrm::OK) {} ~Session()32 virtual ~Session() {} 33 sessionId()34 const std::vector<uint8_t>& sessionId() const { return mSessionId; } 35 36 CdmResponseType getKeyRequest(const std::vector<uint8_t>& initDataType, 37 const std::string& mimeType, 38 CdmKeyType keyType, 39 std::vector<uint8_t>* keyRequest) const; 40 41 CdmResponseType provideKeyResponse(const std::vector<uint8_t>& response); 42 43 CdmResponseType decrypt(const KeyId keyId, const Iv iv, const uint8_t* srcPtr, uint8_t* dstPtr, 44 const std::vector<int32_t>& clearDataLengths, 45 const std::vector<int32_t>& encryptedDataLengths, 46 size_t* bytesDecryptedOut); 47 setMockError(CdmResponseType error)48 void setMockError(CdmResponseType error) { mMockError = error; } getMockError()49 CdmResponseType getMockError() const { return mMockError; } 50 51 private: 52 CLEARKEY_DISALLOW_COPY_AND_ASSIGN(Session); 53 54 const std::vector<uint8_t> mSessionId; 55 KeyMap mKeyMap; 56 ::android::Mutex mMapLock; 57 58 // For mocking error return scenarios 59 CdmResponseType mMockError; 60 }; 61 62 } // namespace clearkeydrm 63