mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
[PM-2713] combine makeDataEncKey methods
This commit is contained in:
@@ -25,8 +25,7 @@ namespace Bit.Core.Abstractions
|
|||||||
Task ClearMasterKeyAsync(string userId = null);
|
Task ClearMasterKeyAsync(string userId = null);
|
||||||
Task<Tuple<UserKey, EncString>> EncryptUserKeyWithMasterKeyAsync(MasterKey masterKey);
|
Task<Tuple<UserKey, EncString>> EncryptUserKeyWithMasterKeyAsync(MasterKey masterKey);
|
||||||
Task<UserKey> DecryptUserKeyWithMasterKeyAsync(MasterKey masterKey, EncString encUserKey = null, string userId = null);
|
Task<UserKey> DecryptUserKeyWithMasterKeyAsync(MasterKey masterKey, EncString encUserKey = null, string userId = null);
|
||||||
Task<Tuple<SymmetricCryptoKey, EncString>> MakeDataEncKeyAsync(UserKey key);
|
Task<Tuple<SymmetricCryptoKey, EncString>> MakeDataEncKeyAsync<TKey>(TKey key) where TKey : SymmetricCryptoKey;
|
||||||
Task<Tuple<SymmetricCryptoKey, EncString>> MakeDataEncKeyAsync(OrgKey key);
|
|
||||||
Task<string> HashMasterKeyAsync(string password, MasterKey key, HashPurpose hashPurpose = HashPurpose.ServerAuthorization);
|
Task<string> HashMasterKeyAsync(string password, MasterKey key, HashPurpose hashPurpose = HashPurpose.ServerAuthorization);
|
||||||
Task SetMasterKeyHashAsync(string keyHash);
|
Task SetMasterKeyHashAsync(string keyHash);
|
||||||
Task<string> GetMasterKeyHashAsync();
|
Task<string> GetMasterKeyHashAsync();
|
||||||
|
|||||||
@@ -184,26 +184,20 @@ namespace Bit.Core.Services
|
|||||||
return new UserKey(decUserKey);
|
return new UserKey(decUserKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Tuple<SymmetricCryptoKey, EncString>> MakeDataEncKeyAsync(UserKey userKey)
|
public async Task<Tuple<SymmetricCryptoKey, EncString>> MakeDataEncKeyAsync<TKey>(TKey key)
|
||||||
|
where TKey : SymmetricCryptoKey
|
||||||
{
|
{
|
||||||
if (userKey is null)
|
if (key is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(userKey));
|
throw new ArgumentNullException(nameof(key));
|
||||||
|
}
|
||||||
|
if (typeof(TKey) != typeof(UserKey) && typeof(TKey) != typeof(OrgKey))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Data encryption keys must be of type UserKey or OrgKey. {typeof(TKey)} unsupported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var newSymKey = await _cryptoFunctionService.RandomBytesAsync(64);
|
var newSymKey = await _cryptoFunctionService.RandomBytesAsync(64);
|
||||||
return await BuildProtectedSymmetricKey(userKey, newSymKey, keyBytes => new SymmetricCryptoKey(keyBytes));
|
return await BuildProtectedSymmetricKey(key, newSymKey, keyBytes => new SymmetricCryptoKey(keyBytes));
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Tuple<SymmetricCryptoKey, EncString>> MakeDataEncKeyAsync(OrgKey orgKey)
|
|
||||||
{
|
|
||||||
if (orgKey is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(orgKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
var newSymKey = await _cryptoFunctionService.RandomBytesAsync(64);
|
|
||||||
return await BuildProtectedSymmetricKey(orgKey, newSymKey, keyBytes => new SymmetricCryptoKey(keyBytes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> HashMasterKeyAsync(string password, MasterKey masterKey, HashPurpose hashPurpose = HashPurpose.ServerAuthorization)
|
public async Task<string> HashMasterKeyAsync(string password, MasterKey masterKey, HashPurpose hashPurpose = HashPurpose.ServerAuthorization)
|
||||||
|
|||||||
Reference in New Issue
Block a user