({armoredKeys})
| 341 | } |
| 342 | |
| 343 | async readArmoredKeys({armoredKeys}) { |
| 344 | const errors = []; |
| 345 | let publicKeys = []; |
| 346 | const privateKeys = []; |
| 347 | if (!armoredKeys.length) { |
| 348 | return; |
| 349 | } |
| 350 | for (const armoredKey of armoredKeys) { |
| 351 | try { |
| 352 | const keys = await readKeys({armoredKeys: armoredKey.armored}); |
| 353 | if (armoredKey.type === 'public') { |
| 354 | publicKeys.push(...keys); |
| 355 | } else { |
| 356 | privateKeys.push(...keys); |
| 357 | } |
| 358 | } catch (e) { |
| 359 | console.log('Error on parsing armored key', e); |
| 360 | errors.push({msg: e.message, code: 'KEY_IMPORT_ERROR_PARSE'}); |
| 361 | } |
| 362 | } |
| 363 | // merge public into private |
| 364 | publicKeys = await filterAsync(publicKeys, async pubKey => { |
| 365 | const pubFpr = pubKey.getFingerprint(); |
| 366 | const privKeyIndex = privateKeys.findIndex(priv => priv.getFingerprint() === pubFpr); |
| 367 | if (privKeyIndex === -1) { |
| 368 | return true; |
| 369 | } |
| 370 | privateKeys[privKeyIndex] = await privateKeys[privKeyIndex].update(pubKey); |
| 371 | }); |
| 372 | const keys = [...publicKeys, ...privateKeys]; |
| 373 | // sanitize keys |
| 374 | const sanitizedKeys = []; |
| 375 | for (const key of keys) { |
| 376 | const saniKey = await sanitizeKey(key); |
| 377 | if (!saniKey) { |
| 378 | errors.push({msg: key.getFingerprint().toUpperCase(), code: 'KEY_IMPORT_ERROR_NO_UID'}); |
| 379 | } else { |
| 380 | sanitizedKeys.push(key); |
| 381 | } |
| 382 | } |
| 383 | const mappedKeys = await mapKeys(sanitizedKeys); |
| 384 | for (const [keyIndex, mappedKey] of mappedKeys.entries()) { |
| 385 | mappedKey.users = []; |
| 386 | for (const [index, user] of keys[keyIndex].users.entries()) { |
| 387 | if (!user.userID) { |
| 388 | // filter out user attribute packages |
| 389 | continue; |
| 390 | } |
| 391 | const userStatus = await verifyUser(user); |
| 392 | const uiUser = {id: index, userId: user.userID.userID, name: user.userID.name, email: user.userID.email, status: userStatus}; |
| 393 | parseUserId(uiUser); |
| 394 | mappedKey.users.push(uiUser); |
| 395 | } |
| 396 | } |
| 397 | const validArmoreds = sanitizedKeys.map(key => ({ |
| 398 | type: key.isPrivate() ? 'private' : 'public', |
| 399 | armored: key.armor() |
| 400 | })); |
nothing calls this directly
no test coverage detected