1 /*
2  * Copyright 2020 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 #include "common/libs/security/keymaster_channel.h"
18 
19 namespace cuttlefish {
20 
operator ()(keymaster_message * ptr)21 void KeymasterCommandDestroyer::operator()(keymaster_message* ptr) {
22   { keymaster::Eraser(ptr, sizeof(keymaster_message) + ptr->payload_size); }
23   std::free(ptr);
24 }
25 
CreateKeymasterMessage(AndroidKeymasterCommand command,bool is_response,size_t payload_size)26 ManagedKeymasterMessage CreateKeymasterMessage(AndroidKeymasterCommand command,
27                                                bool is_response,
28                                                size_t payload_size) {
29   auto memory = std::malloc(payload_size + sizeof(keymaster_message));
30   auto message = reinterpret_cast<keymaster_message*>(memory);
31   message->cmd = command;
32   message->is_response = is_response;
33   message->payload_size = payload_size;
34   return ManagedKeymasterMessage(message);
35 }
36 
37 }  // namespace cuttlefish