• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gatekeeper_channel.h"
18 
19 #include <keymaster/android_keymaster_utils.h>
20 
21 namespace cuttlefish {
22 
operator ()(GatekeeperRawMessage * ptr)23 void GatekeeperCommandDestroyer::operator()(GatekeeperRawMessage* ptr) {
24   {
25     keymaster::Eraser(ptr, sizeof(GatekeeperRawMessage) + ptr->payload_size);
26   }
27   std::free(ptr);
28 }
29 
CreateGatekeeperMessage(uint32_t command,bool is_response,size_t payload_size)30 ManagedGatekeeperMessage CreateGatekeeperMessage(uint32_t command,
31                                                  bool is_response,
32                                                  size_t payload_size) {
33   auto memory = std::malloc(payload_size + sizeof(GatekeeperRawMessage));
34   auto message = reinterpret_cast<GatekeeperRawMessage*>(memory);
35   message->cmd = command;
36   message->is_response = is_response;
37   message->payload_size = payload_size;
38   return ManagedGatekeeperMessage(message);
39 }
40 
41 }  // namespace cuttlefish