mirror of
https://github.com/bitwarden/android.git
synced 2025-01-11 18:57:39 +03:00
sequentialize some methods
This commit is contained in:
parent
c6ce3e9480
commit
7f2c265965
2 changed files with 116 additions and 66 deletions
|
@ -37,6 +37,7 @@ namespace Bit.Core.Services
|
|||
["google.com"] = new HashSet<string> { "script.google.com" }
|
||||
};
|
||||
private readonly HttpClient _httpClient = new HttpClient();
|
||||
private Task<List<CipherView>> _getAllDecryptedTask;
|
||||
|
||||
public CipherService(
|
||||
ICryptoService cryptoService,
|
||||
|
@ -204,13 +205,20 @@ namespace Bit.Core.Services
|
|||
return response?.ToList() ?? new List<Cipher>();
|
||||
}
|
||||
|
||||
// TODO: sequentialize?
|
||||
public async Task<List<CipherView>> GetAllDecryptedAsync()
|
||||
public Task<List<CipherView>> GetAllDecryptedAsync()
|
||||
{
|
||||
if(DecryptedCipherCache != null)
|
||||
{
|
||||
return DecryptedCipherCache;
|
||||
return Task.FromResult(DecryptedCipherCache);
|
||||
}
|
||||
if(_getAllDecryptedTask != null)
|
||||
{
|
||||
return _getAllDecryptedTask;
|
||||
}
|
||||
async Task<List<CipherView>> doTask()
|
||||
{
|
||||
try
|
||||
{
|
||||
var hashKey = await _cryptoService.HasKeyAsync();
|
||||
if(!hashKey)
|
||||
{
|
||||
|
@ -233,6 +241,14 @@ namespace Bit.Core.Services
|
|||
DecryptedCipherCache = decCiphers;
|
||||
return DecryptedCipherCache;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
_getAllDecryptedTask = doTask();
|
||||
return _getAllDecryptedTask;
|
||||
}
|
||||
|
||||
public async Task<List<CipherView>> GetAllDecryptedForGroupingAsync(string groupingId, bool folder = true)
|
||||
{
|
||||
|
|
|
@ -23,6 +23,8 @@ namespace Bit.Core.Services
|
|||
private byte[] _publicKey;
|
||||
private byte[] _privateKey;
|
||||
private Dictionary<string, SymmetricCryptoKey> _orgKeys;
|
||||
private Task<SymmetricCryptoKey> _getEncKeysTask;
|
||||
private Task<Dictionary<string, SymmetricCryptoKey>> _getOrgKeysTask;
|
||||
|
||||
private const string Keys_Key = "key";
|
||||
private const string Keys_EncOrgKeys = "encOrgKeys";
|
||||
|
@ -113,12 +115,20 @@ namespace Bit.Core.Services
|
|||
return keyHash == null ? null : _keyHash;
|
||||
}
|
||||
|
||||
public async Task<SymmetricCryptoKey> GetEncKeyAsync()
|
||||
public Task<SymmetricCryptoKey> GetEncKeyAsync()
|
||||
{
|
||||
if(_encKey != null)
|
||||
{
|
||||
return _encKey;
|
||||
return Task.FromResult(_encKey);
|
||||
}
|
||||
if(_getEncKeysTask != null)
|
||||
{
|
||||
return _getEncKeysTask;
|
||||
}
|
||||
async Task<SymmetricCryptoKey> doTask()
|
||||
{
|
||||
try
|
||||
{
|
||||
var encKey = await _storageService.GetAsync<string>(Keys_EncKey);
|
||||
if(encKey == null)
|
||||
{
|
||||
|
@ -154,6 +164,14 @@ namespace Bit.Core.Services
|
|||
_encKey = new SymmetricCryptoKey(decEncKey);
|
||||
return _encKey;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_getEncKeysTask = null;
|
||||
}
|
||||
}
|
||||
_getEncKeysTask = doTask();
|
||||
return _getEncKeysTask;
|
||||
}
|
||||
|
||||
public async Task<byte[]> GetPublicKeyAsync()
|
||||
{
|
||||
|
@ -200,12 +218,20 @@ namespace Bit.Core.Services
|
|||
return HashPhrase(userFingerprint);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, SymmetricCryptoKey>> GetOrgKeysAsync()
|
||||
public Task<Dictionary<string, SymmetricCryptoKey>> GetOrgKeysAsync()
|
||||
{
|
||||
if(_orgKeys != null && _orgKeys.Count > 0)
|
||||
{
|
||||
return _orgKeys;
|
||||
return Task.FromResult(_orgKeys);
|
||||
}
|
||||
if(_getOrgKeysTask != null)
|
||||
{
|
||||
return _getOrgKeysTask;
|
||||
}
|
||||
async Task<Dictionary<string, SymmetricCryptoKey>> doTask()
|
||||
{
|
||||
try
|
||||
{
|
||||
var encOrgKeys = await _storageService.GetAsync<Dictionary<string, string>>(Keys_EncOrgKeys);
|
||||
if(encOrgKeys == null)
|
||||
{
|
||||
|
@ -226,6 +252,14 @@ namespace Bit.Core.Services
|
|||
}
|
||||
return _orgKeys;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_getOrgKeysTask = null;
|
||||
}
|
||||
}
|
||||
_getOrgKeysTask = doTask();
|
||||
return _getOrgKeysTask;
|
||||
}
|
||||
|
||||
public async Task<SymmetricCryptoKey> GetOrgKeyAsync(string orgId)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue