Skip to content
  • Sponsor
  • Notifications You must be signed in to change notification settings
  • Fork 1.4k

Commit d517de3

Browse files
committedMar 27, 2024·
Implement ReKey on async db
1 parent 7ae942b commit d517de3

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed
 

‎src/SQLite.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ CreateTablesResult CreateTables<T, T2, T3, T4, T5> (CreateFlags createFlags = Cr
244244
List<T> Query<T> (string query, params object[] args) where T : new();
245245
List<object> Query (TableMapping map, string query, params object[] args);
246246
List<T> QueryScalars<T> (string query, params object[] args);
247+
void ReKey (string key);
248+
void ReKey (byte[] key);
247249
void Release (string savepoint);
248250
void Rollback ();
249251
void RollbackTo (string savepoint);
@@ -259,8 +261,7 @@ CreateTablesResult CreateTables<T, T2, T3, T4, T5> (CreateFlags createFlags = Cr
259261
/// An open connection to a SQLite database.
260262
/// </summary>
261263
[Preserve (AllMembers = true)]
262-
public partial class SQLiteConnection : IDisposable
263-
, ISQLiteConnection
264+
public partial class SQLiteConnection : ISQLiteConnection
264265
{
265266
private bool _open;
266267
private TimeSpan _busyTimeout;

‎src/SQLiteAsync.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> (CreateFlags creat
110110
Task<List<T>> QueryAsync<T> (string query, params object[] args) where T : new();
111111
Task<List<object>> QueryAsync (TableMapping map, string query, params object[] args);
112112
Task<List<T>> QueryScalarsAsync<T> (string query, params object[] args);
113+
Task ReKeyAsync (string key);
114+
Task ReKeyAsync (byte[] key);
113115
Task RunInTransactionAsync (Action<SQLiteConnection> action);
114116
Task SetBusyTimeoutAsync (TimeSpan value);
115117
AsyncTableQuery<T> Table<T> () where T : new();
@@ -121,8 +123,7 @@ Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> (CreateFlags creat
121123
/// <summary>
122124
/// A pooled asynchronous connection to a SQLite database.
123125
/// </summary>
124-
public partial class SQLiteAsyncConnection
125-
: ISQLiteAsyncConnection
126+
public partial class SQLiteAsyncConnection : ISQLiteAsyncConnection
126127
{
127128
readonly SQLiteConnectionString _connectionString;
128129

@@ -1265,6 +1266,30 @@ public Task<IEnumerable<object>> DeferredQueryAsync (TableMapping map, string qu
12651266
{
12661267
return ReadAsync (conn => (IEnumerable<object>)conn.DeferredQuery (map, query, args).ToList ());
12671268
}
1269+
1270+
/// <summary>
1271+
/// Change the encryption key for a SQLCipher database with "pragma rekey = ...".
1272+
/// </summary>
1273+
/// <param name="key">Encryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
1274+
public Task ReKeyAsync (string key)
1275+
{
1276+
return WriteAsync<object> (conn => {
1277+
conn.ReKey (key);
1278+
return null;
1279+
});
1280+
}
1281+
1282+
/// <summary>
1283+
/// Change the encryption key for a SQLCipher database.
1284+
/// </summary>
1285+
/// <param name="key">256-bit (32 byte) or 384-bit (48 bytes) encryption key data</param>
1286+
public Task ReKeyAsync (byte[] key)
1287+
{
1288+
return WriteAsync<object> (conn => {
1289+
conn.ReKey (key);
1290+
return null;
1291+
});
1292+
}
12681293
}
12691294

12701295
/// <summary>

0 commit comments

Comments
 (0)
Please sign in to comment.