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 KEYSTORE_OPERATION_STRUCT_H_
18 #define KEYSTORE_OPERATION_STRUCT_H_
19 
20 #include <binder/Binder.h>
21 #include <binder/IBinder.h>
22 #include <keymasterV4_1/Keymaster.h>
23 #include <utils/StrongPointer.h>
24 
25 #include <keystore/keymaster_types.h>
26 #include <keystore/keystore_hidl_support.h>
27 #include <keystore/keystore_return_types.h>
28 
29 #include <future>
30 
31 namespace keystore {
32 
33 using ::android::IBinder;
34 using ::android::sp;
35 using keymaster::support::Keymaster;
36 
37 struct Operation {
38     Operation() = default;
OperationOperation39     Operation(uint64_t handle_, uint64_t keyid_, KeyPurpose purpose_, const sp<Keymaster>& device_,
40               KeyCharacteristics&& characteristics_, sp<IBinder> appToken_,
41               const hidl_vec<KeyParameter> params_)
42         : handle(handle_), keyid(keyid_), purpose(purpose_), device(device_),
43           characteristics(characteristics_), appToken(appToken_), authToken(), verificationToken(),
44           params(params_) {}
45     Operation(Operation&&) = default;
46     Operation(const Operation&) = delete;
47 
hasAuthTokenOperation48     bool hasAuthToken() const { return authToken.mac.size() != 0; }
49 
50     uint64_t handle;
51     uint64_t keyid;
52     KeyPurpose purpose;
53     sp<Keymaster> device;
54     KeyCharacteristics characteristics;
55     sp<IBinder> appToken;
56     std::promise<KeyStoreServiceReturnCode> authTokenPromise;
57     std::future<KeyStoreServiceReturnCode> authTokenFuture;
58     HardwareAuthToken authToken;
59     VerificationToken verificationToken;
60     const hidl_vec<KeyParameter> params;
61 };
62 
63 }  // namespace keystore
64 
65 #endif
66