1 /*
2 * Copyright (C) 2014 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "ClearKeyCryptoPlugin"
19 #include <utils/Log.h>
20
21 #include <utils/Errors.h>
22 #include <utils/StrongPointer.h>
23
24 #include "CryptoFactory.h"
25
26 #include "ClearKeyUUID.h"
27 #include "CryptoPlugin.h"
28 #include "Session.h"
29 #include "SessionLibrary.h"
30
31 namespace clearkeydrm {
32
isCryptoSchemeSupported(const uint8_t uuid[16]) const33 bool CryptoFactory::isCryptoSchemeSupported(const uint8_t uuid[16]) const {
34 return isClearKeyUUID(uuid);
35 }
36
createPlugin(const uint8_t uuid[16],const void * data,size_t size,android::CryptoPlugin ** plugin)37 android::status_t CryptoFactory::createPlugin(
38 const uint8_t uuid[16],
39 const void* data, size_t size,
40 android::CryptoPlugin** plugin) {
41 if (!isCryptoSchemeSupported(uuid)) {
42 *plugin = NULL;
43 return android::BAD_VALUE;
44 }
45
46 android::Vector<uint8_t> sessionId;
47 sessionId.appendArray(reinterpret_cast<const uint8_t*>(data), size);
48
49 CryptoPlugin *clearKeyPlugin = new CryptoPlugin(sessionId);
50 android::status_t result = clearKeyPlugin->getInitStatus();
51 if (result == android::OK) {
52 *plugin = clearKeyPlugin;
53 } else {
54 delete clearKeyPlugin;
55 *plugin = NULL;
56 }
57 return result;
58 }
59
60 } // namespace clearkeydrm
61