Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2018 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 
     17 #ifndef CLEARKEY_SESSION_H_
     18 #define CLEARKEY_SESSION_H_
     19 
     20 #include <utils/Mutex.h>
     21 #include <utils/RefBase.h>
     22 #include <vector>
     23 
     24 #include "ClearKeyTypes.h"
     25 
     26 
     27 namespace android {
     28 namespace hardware {
     29 namespace drm {
     30 namespace V1_2 {
     31 namespace clearkey {
     32 
     33 namespace drm = ::android::hardware::drm;
     34 using drm::V1_0::Status;
     35 using drm::V1_0::SubSample;
     36 
     37 typedef drm::V1_2::Status Status_V1_2;
     38 
     39 class Session : public RefBase {
     40 public:
     41     explicit Session(const std::vector<uint8_t>& sessionId)
     42         : mSessionId(sessionId), mMockError(Status_V1_2::OK) {}
     43     virtual ~Session() {}
     44 
     45     const std::vector<uint8_t>& sessionId() const { return mSessionId; }
     46 
     47     Status getKeyRequest(
     48             const std::vector<uint8_t>& initDataType,
     49             const std::string& mimeType,
     50             V1_0::KeyType keyType,
     51             std::vector<uint8_t>* keyRequest) const;
     52 
     53     Status provideKeyResponse(
     54             const std::vector<uint8_t>& response);
     55 
     56     Status_V1_2 decrypt(
     57             const KeyId keyId, const Iv iv, const uint8_t* srcPtr,
     58             uint8_t* dstPtr, const std::vector<SubSample> subSamples,
     59             size_t* bytesDecryptedOut);
     60 
     61     void setMockError(Status_V1_2 error) {mMockError = error;}
     62     Status_V1_2 getMockError() const {return mMockError;}
     63 
     64 private:
     65     CLEARKEY_DISALLOW_COPY_AND_ASSIGN(Session);
     66 
     67     const std::vector<uint8_t> mSessionId;
     68     KeyMap mKeyMap;
     69     Mutex mMapLock;
     70 
     71     // For mocking error return scenarios
     72     Status_V1_2 mMockError;
     73 };
     74 
     75 } // namespace clearkey
     76 } // namespace V1_2
     77 } // namespace drm
     78 } // namespace hardware
     79 } // namespace android
     80 
     81 #endif // CLEARKEY_SESSION_H_
     82