1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

added q promise library. moving cipher service functions out into application services and domain models.

This commit is contained in:
Kyle Spearrin
2016-09-15 00:09:48 -04:00
parent 2c44bd5cc8
commit 16a59f8d09
8 changed files with 121 additions and 77 deletions

View File

@@ -7,6 +7,45 @@
};
function initSiteService() {
SiteService.prototype.encrypt = function (site) {
var model = {
id: site.id,
folderId: site.folderId,
favorite: site.favorite
};
var deferred = Q.defer();
encryptWithPromise(site.name).then(function (cs) {
model.name = cs;
return encryptWithPromise(site.uri);
}).then(function (cs) {
model.uri = cs;
return encryptWithPromise(site.username);
}).then(function (cs) {
model.username = cs;
return encryptWithPromise(site.password);
}).then(function (cs) {
model.password = cs;
return encryptWithPromise(site.notes);
}).then(function (cs) {
model.notes = cs;
deferred.resolve(model);
});
return deferred.promise;
};
function encryptWithPromise(plaintextString) {
var deferred = Q.defer();
cryptoService.encrypt(plaintextString, function (cipherString) {
deferred.resolve(cipherString);
});
return deferred.promise;
}
SiteService.prototype.get = function (id, callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';