Keystore2.0 database.rs: Add storing and loading key parameters.
This patch adds functionality for storing and loading key parameters.
It also normalizes import names of generated types by importing
SecurityLevel as SecurityLevelType.
It also breaks out loading blob components into its own helper
function.
Bug: 159370859
Test: keystore2_test
Change-Id: I2969c7c467cb3ae9cf8c283122a6f82f775cad37
diff --git a/keystore2/src/key_parameter.rs b/keystore2/src/key_parameter.rs
index 5266c28..ae3d774 100644
--- a/keystore2/src/key_parameter.rs
+++ b/keystore2/src/key_parameter.rs
@@ -33,6 +33,7 @@
use rusqlite::{Result as SqlResult, Row};
/// KeyParameter wraps the KeyParameterValue and the security level at which it is enforced.
+#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct KeyParameter {
key_parameter_value: KeyParameterValue,
security_level: SecurityLevelType,
@@ -40,7 +41,7 @@
/// KeyParameterValue holds a value corresponding to one of the Tags defined in
/// the AIDL spec at hardware/interfaces/keymint
-#[derive(PartialEq, Debug)]
+#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub enum KeyParameterValue {
/// Associated with Tag:INVALID
Invalid,
@@ -238,7 +239,7 @@
#[cfg(test)]
mod basic_tests {
- use crate::key_parameter::*;
+ use super::*;
// Test basic functionality of KeyParameter.
#[test]
@@ -265,6 +266,10 @@
pub struct SqlField<'a>(usize, &'a Row<'a>);
impl<'a> SqlField<'a> {
+ /// Creates a new SqlField with the given index and row.
+ pub fn new(index: usize, row: &'a Row<'a>) -> Self {
+ Self(index, row)
+ }
/// Returns the column value from the row, when we know the expected type.
pub fn get<T: FromSql>(&self) -> SqlResult<T> {
self.1.get(self.0)