Skip to content

Commit

Permalink
Implement ReKey on async db
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed Mar 27, 2024
1 parent 7ae942b commit d517de3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ CreateTablesResult CreateTables<T, T2, T3, T4, T5> (CreateFlags createFlags = Cr
List<T> Query<T> (string query, params object[] args) where T : new();
List<object> Query (TableMapping map, string query, params object[] args);
List<T> QueryScalars<T> (string query, params object[] args);
void ReKey (string key);
void ReKey (byte[] key);
void Release (string savepoint);
void Rollback ();
void RollbackTo (string savepoint);
Expand All @@ -259,8 +261,7 @@ CreateTablesResult CreateTables<T, T2, T3, T4, T5> (CreateFlags createFlags = Cr
/// An open connection to a SQLite database.
/// </summary>
[Preserve (AllMembers = true)]
public partial class SQLiteConnection : IDisposable
, ISQLiteConnection
public partial class SQLiteConnection : ISQLiteConnection
{
private bool _open;
private TimeSpan _busyTimeout;
Expand Down
29 changes: 27 additions & 2 deletions src/SQLiteAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> (CreateFlags creat
Task<List<T>> QueryAsync<T> (string query, params object[] args) where T : new();
Task<List<object>> QueryAsync (TableMapping map, string query, params object[] args);
Task<List<T>> QueryScalarsAsync<T> (string query, params object[] args);
Task ReKeyAsync (string key);
Task ReKeyAsync (byte[] key);
Task RunInTransactionAsync (Action<SQLiteConnection> action);
Task SetBusyTimeoutAsync (TimeSpan value);
AsyncTableQuery<T> Table<T> () where T : new();
Expand All @@ -121,8 +123,7 @@ Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> (CreateFlags creat
/// <summary>
/// A pooled asynchronous connection to a SQLite database.
/// </summary>
public partial class SQLiteAsyncConnection
: ISQLiteAsyncConnection
public partial class SQLiteAsyncConnection : ISQLiteAsyncConnection
{
readonly SQLiteConnectionString _connectionString;

Expand Down Expand Up @@ -1265,6 +1266,30 @@ public Task<IEnumerable<object>> DeferredQueryAsync (TableMapping map, string qu
{
return ReadAsync (conn => (IEnumerable<object>)conn.DeferredQuery (map, query, args).ToList ());
}

/// <summary>
/// Change the encryption key for a SQLCipher database with "pragma rekey = ...".
/// </summary>
/// <param name="key">Encryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
public Task ReKeyAsync (string key)
{
return WriteAsync<object> (conn => {
conn.ReKey (key);
return null;
});
}

/// <summary>
/// Change the encryption key for a SQLCipher database.
/// </summary>
/// <param name="key">256-bit (32 byte) or 384-bit (48 bytes) encryption key data</param>
public Task ReKeyAsync (byte[] key)
{
return WriteAsync<object> (conn => {
conn.ReKey (key);
return null;
});
}
}

/// <summary>
Expand Down

0 comments on commit d517de3

Please sign in to comment.