Skip to content

Commit

Permalink
Enable encryption in the copy method
Browse files Browse the repository at this point in the history
  • Loading branch information
borrrden committed Sep 1, 2017
1 parent f162c43 commit 7548fae
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/Couchbase.Lite/API/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,26 +238,22 @@ public Database(Database other)
public static void Copy(string path, string name, DatabaseConfiguration config)
{
var destPath = DatabasePath(name, config.Directory);
var nativeConfig = DBConfig;
if (config.EncryptionKey != null) {
#if true
throw new NotImplementedException("Encryption is not yet supported");
#else
var key = config.EncryptionKey;
int i = 0;
nativeConfig.encryptionKey.algorithm = C4EncryptionAlgorithm.AES256;
foreach(var b in key.KeyData) {
nativeConfig.encryptionKey.bytes[i++] = b;
}
#endif
}
LiteCoreBridge.Check(err =>
{
var nativeConfig = DBConfig;
if (config.EncryptionKey != null) {
var key = config.EncryptionKey;
int i = 0;
nativeConfig.encryptionKey.algorithm = C4EncryptionAlgorithm.AES256;
foreach (var b in key.KeyData) {
nativeConfig.encryptionKey.bytes[i++] = b;
}
}

LiteCoreBridge.Check(err =>
{
var nativeConfigCopy = nativeConfig;
return Native.c4db_copy(path, destPath, &nativeConfigCopy, err);
});
}
return Native.c4db_copy(path, destPath, &nativeConfig, err);
});

}

/// <summary>
/// Deletes the contents of a database with the given name in the
Expand Down

0 comments on commit 7548fae

Please sign in to comment.