Make Keystore2's crypto operations their own crate

This cleanly separates out the underlying C++ code and allows clients
to depend only on the safe wrapper.

Test: keystore2_crypto_test
Test: keystore2_crypto_test_rust
Change-Id: I730ebe22ac66287a5650a36b7aeb61c69172e0f8
This commit is contained in:
Joel Galenson 2020-11-19 17:58:33 -08:00
parent de5e40df83
commit 46d6fd0ffa
11 changed files with 87 additions and 43 deletions

View file

@ -44,7 +44,6 @@ rust_test {
"libandroid_logger", "libandroid_logger",
"libanyhow", "libanyhow",
"libbinder_rs", "libbinder_rs",
"libkeystore2_crypto_bindgen",
"libkeystore2_selinux", "libkeystore2_selinux",
"liblazy_static", "liblazy_static",
"liblibsqlite3_sys", "liblibsqlite3_sys",
@ -52,28 +51,6 @@ rust_test {
"librusqlite", "librusqlite",
"libthiserror", "libthiserror",
], ],
shared_libs: ["libkeystore2_crypto"],
}
cc_library {
name: "libkeystore2_crypto",
srcs: [
"src/crypto.cpp",
"src/certificate_utils.cpp",
],
export_include_dirs: ["include",],
shared_libs: [
"libcrypto",
"liblog",
],
}
rust_bindgen {
name: "libkeystore2_crypto_bindgen",
wrapper_src: "src/crypto.hpp",
crate_name: "keystore2_crypto_bindgen",
source_stem: "bindings",
host_supported: true,
} }
rust_binary { rust_binary {
@ -87,22 +64,3 @@ rust_binary {
], ],
init_rc: ["keystore2.rc"], init_rc: ["keystore2.rc"],
} }
cc_test {
cflags: [
"-Wall",
"-Werror",
"-Wextra",
],
srcs: [
"src/tests/certificate_utils_test.cpp",
"src/tests/gtest_main.cpp",
],
static_libs: [
"libkeystore2_crypto",
],
shared_libs: [
"libcrypto",
],
name: "keystore2_crypto_test",
}

View file

@ -0,0 +1,84 @@
// Copyright 2020, The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
rust_library {
name: "libkeystore2_crypto_rust",
crate_name: "keystore2_crypto",
srcs: ["lib.rs"],
rustlibs: [
"libkeystore2_crypto_bindgen",
],
static_libs: ["libkeystore2_crypto"],
shared_libs: ["libcrypto"],
}
cc_library {
name: "libkeystore2_crypto",
srcs: [
"crypto.cpp",
"certificate_utils.cpp",
],
export_include_dirs: ["include",],
shared_libs: [
"libcrypto",
"liblog",
],
}
rust_bindgen {
name: "libkeystore2_crypto_bindgen",
wrapper_src: "crypto.hpp",
crate_name: "keystore2_crypto_bindgen",
source_stem: "bindings",
host_supported: true,
}
rust_test {
name: "keystore2_crypto_test_rust",
crate_name: "keystore2_crypto_test_rust",
srcs: ["lib.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
rustlibs: [
"libkeystore2_crypto_bindgen",
"libkeystore2_crypto_rust",
],
static_libs: [
"libkeystore2_crypto",
],
shared_libs: [
"libc++",
"libcrypto",
"liblog",
],
}
cc_test {
cflags: [
"-Wall",
"-Werror",
"-Wextra",
],
srcs: [
"tests/certificate_utils_test.cpp",
"tests/gtest_main.cpp",
],
static_libs: [
"libkeystore2_crypto",
],
shared_libs: [
"libcrypto",
],
name: "keystore2_crypto_test",
}

View file

@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// TODO: Once this is complete, remove this and document everything public.
#![allow(missing_docs)]
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -14,7 +14,6 @@
//! This crate implements the Android Keystore 2.0 service. //! This crate implements the Android Keystore 2.0 service.
mod crypto;
pub mod database; pub mod database;
pub mod error; pub mod error;
pub mod globals; pub mod globals;