1
0
mirror of https://github.com/bitwarden/web synced 2025-12-14 15:23:14 +00:00

add subvault

This commit is contained in:
Kyle Spearrin
2017-03-09 22:08:47 -05:00
parent e7707c4826
commit 429b2b8a21
7 changed files with 139 additions and 45 deletions

View File

@@ -61,21 +61,6 @@ angular
username: decryptProperty(encryptedCipher.Data.Username, key, true)
};
try {
login.name = cryptoService.decrypt(encryptedCipher.Data.Name, key);
}
catch (err) {
login.name = '[error: cannot decrypt]';
}
try {
login.username = encryptedCipher.Data.Username && encryptedCipher.Data.Username !== '' ?
cryptoService.decrypt(encryptedCipher.Data.Username, key) : null;
}
catch (err) {
login.username = '[error: cannot decrypt]';
}
return login;
};
@@ -109,6 +94,31 @@ angular
};
};
_service.decryptSubvaults = function (encryptedSubvaults, orgId, catchError) {
if (!encryptedSubvaults) throw "encryptedSubvaults is undefined or null";
var unencryptedSubvaults = [];
for (var i = 0; i < encryptedSubvaults.length; i++) {
unencryptedSubvaults.push(_service.decryptSubvault(encryptedSubvaults[i], orgId, catchError));
}
return unencryptedSubvaults;
};
_service.decryptSubvault = function (encryptedSubvault, orgId, catchError) {
if (!encryptedSubvault) throw "encryptedSubvault is undefined or null";
catchError = catchError === true ? true : false;
orgId = orgId || encryptedSubvault.OrganizationId;
var key = cryptoService.getOrgKey(orgId);
return {
id: encryptedSubvault.Id,
name: catchError ? decryptProperty(encryptedSubvault.Name, key, false) :
cryptoService.decrypt(encryptedSubvault.Name, key)
};
};
function decryptProperty(property, key, checkEmpty) {
if (checkEmpty && (!property || property === '')) {
return null;
@@ -172,5 +182,25 @@ angular
};
};
_service.encryptSubvaults = function (unencryptedSubvaults, orgId) {
if (!unencryptedSubvaults) throw "unencryptedSubvaults is undefined or null";
var encryptedSubvaults = [];
for (var i = 0; i < unencryptedSubvaults.length; i++) {
encryptedSubvaults.push(_service.encryptSubvault(unencryptedSubvaults[i], orgId));
}
return encryptedSubvaults;
};
_service.encryptSubvault = function (unencryptedSubvault, orgId) {
if (!unencryptedSubvault) throw "unencryptedSubvault is undefined or null";
return {
id: unencryptedSubvault.id,
name: cryptoService.encrypt(unencryptedSubvault.name, cryptoService.getOrgKey(orgId))
};
};
return _service;
});