Update for rusqlite 0.29.0.
Test: atest keystore2_test_utils_test keystore2_test
Change-Id: Ib613f9e11523f16060e4fb473b849203ff26ee2d
diff --git a/keystore2/legacykeystore/lib.rs b/keystore2/legacykeystore/lib.rs
index 464f0a2..b826a65 100644
--- a/keystore2/legacykeystore/lib.rs
+++ b/keystore2/legacykeystore/lib.rs
@@ -29,9 +29,7 @@
legacy_blob::LegacyBlobLoader, maintenance::DeleteListener, maintenance::Domain,
utils::uid_to_android_user, utils::watchdog as wd,
};
-use rusqlite::{
- params, Connection, OptionalExtension, Transaction, TransactionBehavior, NO_PARAMS,
-};
+use rusqlite::{params, Connection, OptionalExtension, Transaction, TransactionBehavior};
use std::sync::Arc;
use std::{
collections::HashSet,
@@ -95,7 +93,7 @@
alias BLOB,
profile BLOB,
UNIQUE(owner, alias));",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"profiles\" table.")?;
Ok(())
diff --git a/keystore2/src/database.rs b/keystore2/src/database.rs
index d7c939c..7d61a29 100644
--- a/keystore2/src/database.rs
+++ b/keystore2/src/database.rs
@@ -82,7 +82,7 @@
types::FromSqlResult,
types::ToSqlOutput,
types::{FromSqlError, Value, ValueRef},
- Connection, OptionalExtension, ToSql, Transaction, TransactionBehavior, NO_PARAMS,
+ Connection, OptionalExtension, ToSql, Transaction, TransactionBehavior,
};
use std::{
@@ -905,21 +905,21 @@
alias BLOB,
state INTEGER,
km_uuid BLOB);",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"keyentry\" table.")?;
tx.execute(
"CREATE INDEX IF NOT EXISTS persistent.keyentry_id_index
ON keyentry(id);",
- NO_PARAMS,
+ [],
)
.context("Failed to create index keyentry_id_index.")?;
tx.execute(
"CREATE INDEX IF NOT EXISTS persistent.keyentry_domain_namespace_index
ON keyentry(domain, namespace, alias);",
- NO_PARAMS,
+ [],
)
.context("Failed to create index keyentry_domain_namespace_index.")?;
@@ -929,14 +929,14 @@
subcomponent_type INTEGER,
keyentryid INTEGER,
blob BLOB);",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"blobentry\" table.")?;
tx.execute(
"CREATE INDEX IF NOT EXISTS persistent.blobentry_keyentryid_index
ON blobentry(keyentryid);",
- NO_PARAMS,
+ [],
)
.context("Failed to create index blobentry_keyentryid_index.")?;
@@ -947,14 +947,14 @@
tag INTEGER,
data ANY,
UNIQUE (blobentryid, tag));",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"blobmetadata\" table.")?;
tx.execute(
"CREATE INDEX IF NOT EXISTS persistent.blobmetadata_blobentryid_index
ON blobmetadata(blobentryid);",
- NO_PARAMS,
+ [],
)
.context("Failed to create index blobmetadata_blobentryid_index.")?;
@@ -964,14 +964,14 @@
tag INTEGER,
data ANY,
security_level INTEGER);",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"keyparameter\" table.")?;
tx.execute(
"CREATE INDEX IF NOT EXISTS persistent.keyparameter_keyentryid_index
ON keyparameter(keyentryid);",
- NO_PARAMS,
+ [],
)
.context("Failed to create index keyparameter_keyentryid_index.")?;
@@ -981,14 +981,14 @@
tag INTEGER,
data ANY,
UNIQUE (keyentryid, tag));",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"keymetadata\" table.")?;
tx.execute(
"CREATE INDEX IF NOT EXISTS persistent.keymetadata_keyentryid_index
ON keymetadata(keyentryid);",
- NO_PARAMS,
+ [],
)
.context("Failed to create index keymetadata_keyentryid_index.")?;
@@ -998,7 +998,7 @@
grantee INTEGER,
keyentryid INTEGER,
access_vector INTEGER);",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"grant\" table.")?;
@@ -1611,7 +1611,7 @@
.context(ks_err!("Failed to insert blob."))?;
if let Some(blob_metadata) = blob_metadata {
let blob_id = tx
- .query_row("SELECT MAX(id) FROM persistent.blobentry;", NO_PARAMS, |row| {
+ .query_row("SELECT MAX(id) FROM persistent.blobentry;", [], |row| {
row.get(0)
})
.context(ks_err!("Failed to get new blob id."))?;
@@ -2859,7 +2859,6 @@
use android_hardware_security_secureclock::aidl::android::hardware::security::secureclock::{
Timestamp::Timestamp,
};
- use rusqlite::NO_PARAMS;
use rusqlite::TransactionBehavior;
use std::cell::RefCell;
use std::collections::BTreeMap;
@@ -2898,7 +2897,7 @@
#[test]
fn datetime() -> Result<()> {
let conn = Connection::open_in_memory()?;
- conn.execute("CREATE TABLE test (ts DATETIME);", NO_PARAMS)?;
+ conn.execute("CREATE TABLE test (ts DATETIME);", [])?;
let now = SystemTime::now();
let duration = Duration::from_secs(1000);
let then = now.checked_sub(duration).unwrap();
@@ -2908,7 +2907,7 @@
params![DateTime::try_from(now)?, DateTime::try_from(then)?, DateTime::try_from(soon)?],
)?;
let mut stmt = conn.prepare("SELECT ts FROM test ORDER BY ts ASC;")?;
- let mut rows = stmt.query(NO_PARAMS)?;
+ let mut rows = stmt.query([])?;
assert_eq!(DateTime::try_from(then)?, rows.next()?.unwrap().get(0)?);
assert_eq!(DateTime::try_from(now)?, rows.next()?.unwrap().get(0)?);
assert_eq!(DateTime::try_from(soon)?, rows.next()?.unwrap().get(0)?);
@@ -3259,15 +3258,9 @@
let mut stmt = db
.conn
.prepare("SELECT id, grantee, keyentryid, access_vector FROM persistent.grant;")?;
- let mut rows =
- stmt.query_map::<(i64, u32, i64, KeyPermSet), _, _>(NO_PARAMS, |row| {
- Ok((
- row.get(0)?,
- row.get(1)?,
- row.get(2)?,
- KeyPermSet::from(row.get::<_, i32>(3)?),
- ))
- })?;
+ let mut rows = stmt.query_map::<(i64, u32, i64, KeyPermSet), _, _>([], |row| {
+ Ok((row.get(0)?, row.get(1)?, row.get(2)?, KeyPermSet::from(row.get::<_, i32>(3)?)))
+ })?;
let r = rows.next().unwrap().unwrap();
assert_eq!(r, (next_random, GRANTEE_UID, 1, PVEC1));
@@ -3311,7 +3304,7 @@
ORDER BY subcomponent_type ASC;",
)?;
let mut rows = stmt
- .query_map::<((SubComponentType, i64, Vec<u8>), i64), _, _>(NO_PARAMS, |row| {
+ .query_map::<((SubComponentType, i64, Vec<u8>), i64), _, _>([], |row| {
Ok(((row.get(0)?, row.get(1)?, row.get(2)?), row.get(3)?))
})?;
let (r, id) = rows.next().unwrap().unwrap();
@@ -4412,7 +4405,7 @@
fn get_keyentry(db: &KeystoreDB) -> Result<Vec<KeyEntryRow>> {
db.conn
.prepare("SELECT * FROM persistent.keyentry;")?
- .query_map(NO_PARAMS, |row| {
+ .query_map([], |row| {
Ok(KeyEntryRow {
id: row.get(0)?,
key_type: row.get(1)?,
@@ -4784,7 +4777,7 @@
"SELECT id, key_type, domain, namespace, alias, state, km_uuid FROM persistent.keyentry;",
)?;
let rows = stmt.query_map::<(i64, KeyType, i32, i64, String, KeyLifeCycle, Uuid), _, _>(
- NO_PARAMS,
+ [],
|row| {
Ok((
row.get(0)?,
@@ -4813,7 +4806,7 @@
let mut stmt = db
.conn
.prepare("SELECT id, grantee, keyentryid, access_vector FROM persistent.grant;")?;
- let rows = stmt.query_map::<(i64, i64, i64, i64), _, _>(NO_PARAMS, |row| {
+ let rows = stmt.query_map::<(i64, i64, i64, i64), _, _>([], |row| {
Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?))
})?;
diff --git a/keystore2/src/database/versioning.rs b/keystore2/src/database/versioning.rs
index e3a95c8..2c816f4 100644
--- a/keystore2/src/database/versioning.rs
+++ b/keystore2/src/database/versioning.rs
@@ -13,21 +13,19 @@
// limitations under the License.
use anyhow::{anyhow, Context, Result};
-use rusqlite::{params, OptionalExtension, Transaction, NO_PARAMS};
+use rusqlite::{params, OptionalExtension, Transaction};
pub fn create_or_get_version(tx: &Transaction, current_version: u32) -> Result<u32> {
tx.execute(
"CREATE TABLE IF NOT EXISTS persistent.version (
id INTEGER PRIMARY KEY,
version INTEGER);",
- NO_PARAMS,
+ [],
)
.context("In create_or_get_version: Failed to create version table.")?;
let version = tx
- .query_row("SELECT version FROM persistent.version WHERE id = 0;", NO_PARAMS, |row| {
- row.get(0)
- })
+ .query_row("SELECT version FROM persistent.version WHERE id = 0;", [], |row| row.get(0))
.optional()
.context("In create_or_get_version: Failed to read version.")?;
@@ -44,7 +42,7 @@
.query_row(
"SELECT name FROM persistent.sqlite_master
WHERE type = 'table' AND name = 'keyentry';",
- NO_PARAMS,
+ [],
|_| Ok(()),
)
.optional()
@@ -94,12 +92,12 @@
#[cfg(test)]
mod test {
use super::*;
- use rusqlite::{Connection, TransactionBehavior, NO_PARAMS};
+ use rusqlite::{Connection, TransactionBehavior};
#[test]
fn upgrade_database_test() {
let mut conn = Connection::open_in_memory().unwrap();
- conn.execute("ATTACH DATABASE 'file::memory:' as persistent;", NO_PARAMS).unwrap();
+ conn.execute("ATTACH DATABASE 'file::memory:' as persistent;", []).unwrap();
let upgraders: Vec<_> = (0..30_u32)
.map(move |i| {
@@ -125,19 +123,19 @@
alias BLOB,
state INTEGER,
km_uuid BLOB);",
- NO_PARAMS,
+ [],
)
.unwrap();
}
for from in 1..29 {
for to in from..30 {
- conn.execute("DROP TABLE IF EXISTS persistent.version;", NO_PARAMS).unwrap();
- conn.execute("DROP TABLE IF EXISTS persistent.test;", NO_PARAMS).unwrap();
+ conn.execute("DROP TABLE IF EXISTS persistent.version;", []).unwrap();
+ conn.execute("DROP TABLE IF EXISTS persistent.test;", []).unwrap();
conn.execute(
"CREATE TABLE IF NOT EXISTS persistent.test (
id INTEGER PRIMARY KEY,
test_field INTEGER);",
- NO_PARAMS,
+ [],
)
.unwrap();
@@ -163,7 +161,7 @@
to - from,
conn.query_row(
"SELECT COUNT(test_field) FROM persistent.test;",
- NO_PARAMS,
+ [],
|row| row.get(0)
)
.unwrap()
@@ -188,7 +186,7 @@
#[test]
fn create_or_get_version_new_database() {
let mut conn = Connection::open_in_memory().unwrap();
- conn.execute("ATTACH DATABASE 'file::memory:' as persistent;", NO_PARAMS).unwrap();
+ conn.execute("ATTACH DATABASE 'file::memory:' as persistent;", []).unwrap();
{
let tx = conn.transaction_with_behavior(TransactionBehavior::Immediate).unwrap();
let version = create_or_get_version(&tx, 3).unwrap();
@@ -202,7 +200,7 @@
conn.query_row(
"SELECT name FROM persistent.sqlite_master
WHERE type = 'table' AND name = 'version';",
- NO_PARAMS,
+ [],
|row| row.get(0),
)
);
@@ -210,18 +208,14 @@
// There is exactly one row in the version table.
assert_eq!(
Ok(1),
- conn.query_row("SELECT COUNT(id) from persistent.version;", NO_PARAMS, |row| row
- .get(0))
+ conn.query_row("SELECT COUNT(id) from persistent.version;", [], |row| row.get(0))
);
// The version must be set to 3
assert_eq!(
Ok(3),
- conn.query_row(
- "SELECT version from persistent.version WHERE id = 0;",
- NO_PARAMS,
- |row| row.get(0)
- )
+ conn.query_row("SELECT version from persistent.version WHERE id = 0;", [], |row| row
+ .get(0))
);
// Will subsequent calls to create_or_get_version still return the same version even
@@ -236,8 +230,7 @@
// There is still exactly one row in the version table.
assert_eq!(
Ok(1),
- conn.query_row("SELECT COUNT(id) from persistent.version;", NO_PARAMS, |row| row
- .get(0))
+ conn.query_row("SELECT COUNT(id) from persistent.version;", [], |row| row.get(0))
);
// Bump the version.
@@ -258,25 +251,21 @@
// There is still exactly one row in the version table.
assert_eq!(
Ok(1),
- conn.query_row("SELECT COUNT(id) from persistent.version;", NO_PARAMS, |row| row
- .get(0))
+ conn.query_row("SELECT COUNT(id) from persistent.version;", [], |row| row.get(0))
);
// The version must be set to 5
assert_eq!(
Ok(5),
- conn.query_row(
- "SELECT version from persistent.version WHERE id = 0;",
- NO_PARAMS,
- |row| row.get(0)
- )
+ conn.query_row("SELECT version from persistent.version WHERE id = 0;", [], |row| row
+ .get(0))
);
}
#[test]
fn create_or_get_version_legacy_database() {
let mut conn = Connection::open_in_memory().unwrap();
- conn.execute("ATTACH DATABASE 'file::memory:' as persistent;", NO_PARAMS).unwrap();
+ conn.execute("ATTACH DATABASE 'file::memory:' as persistent;", []).unwrap();
// A legacy (version 0) database is detected if the keyentry table exists but no
// version table.
conn.execute(
@@ -288,7 +277,7 @@
alias BLOB,
state INTEGER,
km_uuid BLOB);",
- NO_PARAMS,
+ [],
)
.unwrap();
@@ -306,7 +295,7 @@
conn.query_row(
"SELECT name FROM persistent.sqlite_master
WHERE type = 'table' AND name = 'version';",
- NO_PARAMS,
+ [],
|row| row.get(0),
)
);
@@ -314,18 +303,14 @@
// There is exactly one row in the version table.
assert_eq!(
Ok(1),
- conn.query_row("SELECT COUNT(id) from persistent.version;", NO_PARAMS, |row| row
- .get(0))
+ conn.query_row("SELECT COUNT(id) from persistent.version;", [], |row| row.get(0))
);
// The version must be set to 0
assert_eq!(
Ok(0),
- conn.query_row(
- "SELECT version from persistent.version WHERE id = 0;",
- NO_PARAMS,
- |row| row.get(0)
- )
+ conn.query_row("SELECT version from persistent.version WHERE id = 0;", [], |row| row
+ .get(0))
);
// Will subsequent calls to create_or_get_version still return the same version even
@@ -340,8 +325,7 @@
// There is still exactly one row in the version table.
assert_eq!(
Ok(1),
- conn.query_row("SELECT COUNT(id) from persistent.version;", NO_PARAMS, |row| row
- .get(0))
+ conn.query_row("SELECT COUNT(id) from persistent.version;", [], |row| row.get(0))
);
// Bump the version.
@@ -362,18 +346,14 @@
// There is still exactly one row in the version table.
assert_eq!(
Ok(1),
- conn.query_row("SELECT COUNT(id) from persistent.version;", NO_PARAMS, |row| row
- .get(0))
+ conn.query_row("SELECT COUNT(id) from persistent.version;", [], |row| row.get(0))
);
// The version must be set to 5
assert_eq!(
Ok(5),
- conn.query_row(
- "SELECT version from persistent.version WHERE id = 0;",
- NO_PARAMS,
- |row| row.get(0)
- )
+ conn.query_row("SELECT version from persistent.version WHERE id = 0;", [], |row| row
+ .get(0))
);
}
}
diff --git a/keystore2/src/key_parameter.rs b/keystore2/src/key_parameter.rs
index 5da95d9..02a1f16 100644
--- a/keystore2/src/key_parameter.rs
+++ b/keystore2/src/key_parameter.rs
@@ -1216,7 +1216,7 @@
use crate::key_parameter::*;
use anyhow::Result;
use rusqlite::types::ToSql;
- use rusqlite::{params, Connection, NO_PARAMS};
+ use rusqlite::{params, Connection};
/// Test initializing a KeyParameter (with key parameter value corresponding to an enum of i32)
/// from a database table row.
@@ -1423,7 +1423,7 @@
tag INTEGER,
data ANY,
security_level INTEGER);",
- NO_PARAMS,
+ [],
)
.context("Failed to initialize \"keyparameter\" table.")?;
Ok(db)
@@ -1459,7 +1459,7 @@
fn query_from_keyparameter(db: &Connection) -> Result<KeyParameter> {
let mut stmt =
db.prepare("SELECT tag, data, security_level FROM persistent.keyparameter")?;
- let mut rows = stmt.query(NO_PARAMS)?;
+ let mut rows = stmt.query([])?;
let row = rows.next()?.unwrap();
KeyParameter::new_from_sql(
Tag(row.get(0)?),