MCPcopy
hub / github.com/mailvelope/mailvelope / importPublicKey

Method importPublicKey

src/modules/KeyringLocal.js:103–150  ·  view source on GitHub ↗
(armored)

Source from the content-addressed store, hash-verified

101 }
102
103 async importPublicKey(armored) {
104 const result = [];
105 let pubKeys;
106 try {
107 pubKeys = await readKeys({armoredKeys: armored});
108 } catch (e) {
109 console.log('Error parsing armored key:', e);
110 result.push({
111 type: 'error',
112 message: l10n.get('key_import_public_read', [e.message])
113 });
114 }
115 for (let pubKey of pubKeys) {
116 if (pubKey.isPrivate()) {
117 result.push({type: 'error', message: l10n.get('key_import_public_read', 'Internal error')});
118 continue;
119 }
120 // check for existing keys
121 checkKeyId(pubKey, this.keystore);
122 const fingerprint = pubKey.getFingerprint();
123 const keyId = pubKey.getKeyID().toHex().toUpperCase();
124 pubKey = await sanitizeKey(pubKey);
125 if (!pubKey) {
126 result.push({
127 type: 'error',
128 message: l10n.get('key_import_error_no_uid', [keyId])
129 });
130 continue;
131 }
132 const {userId} = await getUserInfo(pubKey);
133 const key = this.keystore.getKeysForId(fingerprint);
134 if (key) {
135 await this.updateKey({srcKey: pubKey, destKey: key[0], store: false});
136 result.push({
137 type: 'success',
138 message: l10n.get('key_import_public_update', [keyId, userId])
139 });
140 } else {
141 this.keystore.publicKeys.push(pubKey);
142 result.push({
143 type: 'success',
144 message: l10n.get('key_import_public_success', [keyId, userId])
145 });
146 await this.sync.add(fingerprint, keyringSync.INSERT);
147 }
148 }
149 return result;
150 }
151
152 async importPrivateKey(armored) {
153 const result = [];

Callers 1

importKeysMethod · 0.95

Calls 11

updateKeyMethod · 0.95
checkKeyIdFunction · 0.90
sanitizeKeyFunction · 0.90
getUserInfoFunction · 0.90
isPrivateMethod · 0.80
toHexMethod · 0.80
getKeysForIdMethod · 0.80
addMethod · 0.80
pushMethod · 0.45
getMethod · 0.45
getKeyIDMethod · 0.45

Tested by

no test coverage detected