RecordMgr_get: async + async/yield -> sync.

This commit is contained in:
Edward Lee 2009-06-04 16:50:57 -07:00
parent 8bb5863f50
commit de24904b92
5 changed files with 19 additions and 28 deletions

View File

@ -81,9 +81,9 @@ CryptoWrapper.prototype = {
}
let pubkey = yield PubKeys.getDefaultKey(self.cb);
let privkey = yield PrivKeys.get(self.cb, pubkey.privateKeyUri);
let privkey = PrivKeys.get(pubkey.privateKeyUri);
let meta = yield CryptoMetas.get(self.cb, this.encryption);
let meta = CryptoMetas.get(this.encryption);
let symkey = yield meta.getKey(self.cb, privkey, passphrase);
this.ciphertext = Svc.Crypto.encrypt(JSON.stringify([this.cleartext]),
@ -106,9 +106,9 @@ CryptoWrapper.prototype = {
}
let pubkey = yield PubKeys.getDefaultKey(self.cb);
let privkey = yield PrivKeys.get(self.cb, pubkey.privateKeyUri);
let privkey = PrivKeys.get(pubkey.privateKeyUri);
let meta = yield CryptoMetas.get(self.cb, this.encryption);
let meta = CryptoMetas.get(this.encryption);
let symkey = yield meta.getKey(self.cb, privkey, passphrase);
// note: payload is wrapped in an array, see _encrypt

View File

@ -152,7 +152,7 @@ PubKeyManager.prototype = {
getDefaultKey: function KeyMgr_getDefaultKey(onComplete) {
let fn = function KeyMgr__getDefaultKey() {
let self = yield;
let ret = yield this.get(self.cb, this.defaultKeyUri);
let ret = this.get(this.defaultKeyUri);
self.done(ret);
};
fn.async(this, onComplete);

View File

@ -163,28 +163,19 @@ RecordManager.prototype = {
}
},
get: function RegordMgr_get(onComplete, url) {
let fn = function RegordMgr__get(url) {
let self = yield;
get: function RecordMgr_get(url) {
// Note: using url object directly as key for this._records cache does not
// work because different url objects (even pointing to the same place) are
// different objects and therefore not equal. So always use the string, not
// the object, as a key.
// TODO: use the string as key for this._aliases as well? (Don't know)
let spec = url.spec ? url.spec : url;
if (spec in this._records)
return this._records[spec];
let record = null;
let spec = url.spec? url.spec : url;
/* Note: using url object directly as key for this._records cache
* does not work because different url objects (even pointing to the
* same place) are different objects and therefore not equal. So
* always use the string, not the object, as a key. TODO: use the
* string as key for this._aliases as well? (Don't know) */
if (url in this._aliases)
url = this._aliases[url];
if (spec in this._records)
record = this._records[spec];
if (!record)
record = this.import(url);
self.done(record);
};
fn.async(this, onComplete, url);
if (url in this._aliases)
url = this._aliases[url];
return this.import(url);
},
set: function RegordMgr_set(url, record) {

View File

@ -301,7 +301,7 @@ SyncEngine.prototype = {
this._log.debug("Ensuring server crypto records are there");
let meta = yield CryptoMetas.get(self.cb, this.cryptoMetaURL);
let meta = CryptoMetas.get(this.cryptoMetaURL);
if (!meta) {
let symkey = Svc.Crypto.generateRandomKey();
let pubkey = yield PubKeys.getDefaultKey(self.cb);

View File

@ -719,7 +719,7 @@ WeaveSvc.prototype = {
this._log.debug("Public key has no key data");
else {
// make sure we have a matching privkey
let privkey = yield PrivKeys.get(self.cb, pubkey.privateKeyUri);
let privkey = PrivKeys.get(pubkey.privateKeyUri);
if (!privkey)
this._log.debug("Could not get private key");
else if (privkey.keyData == null)