Alan Stokes | 14f0739 | 2021-09-27 14:03:31 +0100 | [diff] [blame^] | 1 | // 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 | |
| 17 | pub use ffi::*; |
| 18 | |
| 19 | #[cxx::bridge] |
| 20 | mod 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 | } |