MCPcopy Create free account
hub / github.com/WICG/webpackage / parseMaybeEncryptedKey

Function parseMaybeEncryptedKey

js/sign/src/utils/cli-utils.ts:24–57  ·  view source on GitHub ↗
(
  data: Buffer,
  description: string = ''
)

Source from the content-addressed store, hash-verified

22
23// Exported for testing.
24export async function parseMaybeEncryptedKey(
25 data: Buffer,
26 description: string = ''
27): Promise<KeyObject> {
28 // Read unencrypted private key.
29 try {
30 return parsePemKey(data);
31 } catch {
32 infoLog('The provided key is probably encrypted. Decrypting attempt...');
33 }
34
35 const hasEnvVarSet =
36 process.env.WEB_BUNDLE_SIGNING_PASSPHRASE &&
37 process.env.WEB_BUNDLE_SIGNING_PASSPHRASE !== '';
38
39 // Read encrypted private key.
40 try {
41 return parsePemKey(
42 data,
43 hasEnvVarSet
44 ? process.env.WEB_BUNDLE_SIGNING_PASSPHRASE
45 : await readPassphrase(description)
46 );
47 } catch (err) {
48 throw Error(
49 `Failed decrypting encrypted private key with passphrase read from ${
50 hasEnvVarSet
51 ? '`WEB_BUNDLE_SIGNING_PASSPHRASE` environment variable'
52 : 'prompt'
53 }`,
54 { cause: err }
55 );
56 }
57}
58
59// A helper function that can be used to get the passphrase to decrypt a
60// password-decrypted private key from user.

Callers 2

parseRemovalKeyFunction · 0.90

Calls 3

parsePemKeyFunction · 0.90
infoLogFunction · 0.85
readPassphraseFunction · 0.85

Tested by

no test coverage detected