1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #if defined(CODE_ENCRYPTION_ENABLE)
16 #include <sys/ioctl.h>
17 #include <sys/types.h>
18 #endif
19 #include "ecmascript/ohos/code_decrypt.h"
20
21 namespace panda::ecmascript::ohos {
22 #if defined(CODE_ENCRYPTION_ENABLE)
DecryptSetKey(int fd, int srcAppId)23 int DecryptSetKey(int fd, int srcAppId)
24 {
25 struct code_decrypto_arg arg;
26 arg.arg1_len = sizeof(srcAppId);
27 arg.arg1 = reinterpret_cast<void*>(&srcAppId);
28 arg.arg2_len = 0;
29 arg.arg2 = nullptr;
30 return ioctl(fd, CODE_DECRYPT_CMD_SET_KEY, &arg);
31 }
32
DecrypRemoveKey(int fd, int srcAppId)33 int DecrypRemoveKey(int fd, int srcAppId)
34 {
35 struct code_decrypto_arg arg;
36 arg.arg1_len = sizeof(srcAppId);
37 arg.arg1 = reinterpret_cast<void*>(&srcAppId);
38 arg.arg2_len = 0;
39 arg.arg2 = nullptr;
40 return ioctl(fd, CODE_DECRYPT_CMD_REMOVE_KEY, &arg);
41 }
42
DecryptAssociateKey(int fd, int dstAppId, int srcAppId)43 int DecryptAssociateKey(int fd, int dstAppId, int srcAppId)
44 {
45 struct code_decrypto_arg arg;
46 arg.arg1_len = sizeof(dstAppId);
47 arg.arg1 = reinterpret_cast<void*>(&dstAppId);
48 arg.arg2_len = sizeof(srcAppId);
49 arg.arg2 = reinterpret_cast<void*>(&srcAppId);
50 return ioctl(fd, CODE_DECRYPT_CMD_SET_ASSOCIATE_KEY, &arg);
51 }
52
DecrypRemoveAssociateKey(int fd, int dstAppId, int srcAppId)53 int DecrypRemoveAssociateKey(int fd, int dstAppId, int srcAppId)
54 {
55 struct code_decrypto_arg arg;
56 arg.arg1_len = sizeof(dstAppId);
57 arg.arg1 = reinterpret_cast<void*>(&dstAppId);
58 arg.arg2_len = sizeof(srcAppId);
59 arg.arg2 = reinterpret_cast<void*>(&srcAppId);
60 return ioctl(fd, CODE_DECRYPT_CMD_REMOVE_ASSOCIATE_KEY, &arg);
61 }
62 #endif
63 } // namespace panda::ecmascript::ohos