Skip to content

Instantly share code, notes, and snippets.

@koto
Created July 17, 2015 11:01
Show Gist options
  • Save koto/e52022050e2828ee40bb to your computer and use it in GitHub Desktop.
Save koto/e52022050e2828ee40bb to your computer and use it in GitHub Desktop.
spot the bug.
/**
* Imports a public key to the key server.
* @param {!e2e.openpgp.block.TransferablePublicKey} key The ASCII
* armored or {e2e.openpgp.block.TransferablePublicKey} key to import.
* @return {!e2e.async.Result.<boolean>} True if importing key is succeeded.
*/
e2e.openpgp.KeyClient.prototype.importPublicKey = function(key) {
var uids = key.getUserIds();
if (uids.length != 1) {
throw new Error('Invalid user ID for key import.');
}
var nonce = goog.crypt.byteArrayToHex(e2e.random.getRandomBytes(16));
var serializedKey = e2e.openpgp.asciiArmor.encode(
'PUBLIC KEY BLOCK', key.serialize());
return this.getOpenIdCredentials_(uids[0], nonce).addCallback(
goog.bind(this.importKeyWithCredentials_, this, nonce, serializedKey));
};
//....
return this.keyGenerator_.generateKey(email, keyAlgo, keyLength, subkeyAlgo,
subkeyLength, opt_keyLocation).addCallback(function(keys) {
goog.array.forEach(keys, function(key) {
if (key instanceof e2e.openpgp.block.TransferableSecretKey) {
this.importKey_(email, key, this.pubKeyRing_);
if (this.keyClient_ !== null) {
this.keyClient_.importPublicKey(key);
}
} else if (key instanceof e2e.openpgp.block.TransferableSecretKey) {
this.importKey_(email, key, this.privKeyRing_);
}
}, this);
}, this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment