1 /*
2  * Copyright (C) 2017 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 CLEAR_KEY_FETCHER_H_
18 #define CLEAR_KEY_FETCHER_H_
19 
20 #include <vector>
21 
22 #include "protos/license_protos.pb.h"
23 
24 #include <media/stagefright/foundation/ABase.h>
25 #include "KeyFetcher.h"
26 
27 namespace android {
28 namespace clearkeycas {
29 
30 class LicenseFetcher;
31 
32 class ClearKeyFetcher : public KeyFetcher {
33 public:
34     // ClearKeyFetcher takes ownership of |license_fetcher|.
35     explicit ClearKeyFetcher(
36             std::unique_ptr<LicenseFetcher> license_fetcher);
37 
38     virtual ~ClearKeyFetcher();
39 
40     // Initializes the fetcher. Must be called before ObtainKey.
41     status_t Init() override;
42 
43     // Obtains the |asset_id| and |keys| from the Ecm contained in |ecm|.
44     // Returns
45     // - errors returned by EcmContainer::Parse.
46     // - errors returned by ClassicLicenseFetcher::FetchLicense.
47     // - errors returned by Ecm::Decrypt.
48     // |asset_id| and |keys| are owned by the caller and cannot be null.
49     // Init() must have been called.
50     status_t ObtainKey(const sp<ABuffer>& ecm, uint64_t* asset_id,
51             std::vector<KeyInfo>* keys) override;
52 
53 private:
54     clearkeycas::Asset asset_;
55     bool initialized_;
56     std::unique_ptr<LicenseFetcher> license_fetcher_;
57 
58     DISALLOW_EVIL_CONSTRUCTORS(ClearKeyFetcher);
59 };
60 
61 } // namespace clearkeycas
62 } // namespace android
63 
64 #endif  // CLEAR_KEY_FETCHER_H_
65