blob: ace9600b2d4c17a664f9d3967a13ef754b78dae9 [file] [log] [blame]
Alan Stokes14f07392021-09-27 14:03:31 +01001// Copyright 2021, The Android Open Source Project
2//
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//! Bindings native helpers for composd.
16
17pub use ffi::*;
18
19#[cxx::bridge]
20mod ffi {
21 /// Contains either a key or a reason why the key could not be extracted.
22 struct KeyResult {
23 /// The extracted key. If empty, the attempt to extract the key failed.
24 key: Vec<u8>,
25 /// A description of what went wrong if the attempt failed.
26 error: String,
27 }
28
29 unsafe extern "C++" {
30 include!("composd_native.h");
31
32 // SAFETY: The C++ implementation manages its own memory, and does not retain or abuse
33 // the der_certificate reference. cxx handles the mapping of the return value.
34
35 /// Parse the supplied DER X.509 certificate and extract the subject's RsaPublicKey.
36 fn extract_rsa_public_key(der_certificate: &[u8]) -> KeyResult;
37 }
38}