@@ -15,6 +15,7 @@ import type {
15
15
PrivateKey , Signature , SignatureFormatType ,
16
16
} from ' sshpk' ;
17
17
import { Base64 } from ' js-base64' ;
18
+ import * as openpgp from ' openpgp' ;
18
19
import { useDownloadFileFromBase64 } from ' @/composable/downloadBase64' ;
19
20
20
21
function buf2Hex(buffer : ArrayBuffer ) { // buffer is an ArrayBuffer
@@ -59,7 +60,7 @@ interface LabelValue {
59
60
value: string
60
61
multiline? : boolean
61
62
}
62
- const parsedSections = computed <LabelValue []>(() => {
63
+ const parsedSections = computedAsync <LabelValue []>(async () => {
63
64
try {
64
65
certificateX509DER .value = ' ' ;
65
66
const onErrorReturnErrorMessage = (func : () => any ) => {
@@ -78,6 +79,14 @@ const parsedSections = computed<LabelValue[]>(() => {
78
79
return null ;
79
80
}
80
81
};
82
+ const canParseAsync = async (value : string | Buffer , parseFunction : (value : string | Buffer ) => Promise <any >) => {
83
+ try {
84
+ return await parseFunction (value );
85
+ }
86
+ catch {
87
+ return null ;
88
+ }
89
+ };
81
90
const inputKeyOrCertificateValue
82
91
= inputKeyOrCertificate .value !== ' '
83
92
? inputKeyOrCertificate .value
@@ -263,6 +272,74 @@ const parsedSections = computed<LabelValue[]>(() => {
263
272
] as LabelValue [];
264
273
}
265
274
275
+ const pgpPrivateKey = await canParseAsync (inputKeyOrCertificateValue , value => openpgp .readPrivateKey ({ armoredKey: value .toString () })) as openpgp .Key ;
276
+ if (pgpPrivateKey ) {
277
+ return [
278
+ {
279
+ label: ' Type: ' ,
280
+ value: ' PGP Private Key' ,
281
+ },
282
+ {
283
+ label: ' : ' ,
284
+ value: pgpPrivateKey .getCreationTime ().toString (),
285
+ },
286
+ {
287
+ label: ' : ' ,
288
+ value: (await pgpPrivateKey .getExpirationTime ())?.toString () || ' ' ,
289
+ },
290
+ {
291
+ label: ' Algorithm Info: ' ,
292
+ value: JSON .stringify (pgpPrivateKey .getAlgorithmInfo ()),
293
+ },
294
+ {
295
+ label: ' Fingerprint: ' ,
296
+ value: pgpPrivateKey .getFingerprint (),
297
+ },
298
+ {
299
+ label: ' User ID(s): ' ,
300
+ value: pgpPrivateKey .getUserIDs ().join (' , ' ),
301
+ },
302
+ {
303
+ label: ' Key ID(s): ' ,
304
+ value: pgpPrivateKey .getKeyIDs ().map (k => k .toString ()).join (' ; ' ),
305
+ },
306
+ ] as LabelValue [];
307
+ }
308
+
309
+ const pgpPublicKey = await canParseAsync (inputKeyOrCertificateValue , value => openpgp .readKey ({ armoredKey: value .toString () })) as openpgp .Key ;
310
+ if (pgpPublicKey ) {
311
+ return [
312
+ {
313
+ label: ' Type: ' ,
314
+ value: ' PGP Public Key' ,
315
+ },
316
+ {
317
+ label: ' : ' ,
318
+ value: pgpPublicKey .getCreationTime ().toString (),
319
+ },
320
+ {
321
+ label: ' : ' ,
322
+ value: (await pgpPublicKey .getExpirationTime ())?.toString () || ' ' ,
323
+ },
324
+ {
325
+ label: ' Algorithm Info: ' ,
326
+ value: JSON .stringify (pgpPublicKey .getAlgorithmInfo ()),
327
+ },
328
+ {
329
+ label: ' Fingerprint: ' ,
330
+ value: pgpPublicKey .getFingerprint (),
331
+ },
332
+ {
333
+ label: ' User ID(s): ' ,
334
+ value: pgpPublicKey .getUserIDs ().join (' , ' ),
335
+ },
336
+ {
337
+ label: ' Key ID(s): ' ,
338
+ value: pgpPublicKey .getKeyIDs ().map (k => k .toString ()).join (' ; ' ),
339
+ },
340
+ ] as LabelValue [];
341
+ }
342
+
266
343
const signature = canParse (inputKeyOrCertificateValue , (value ) => {
267
344
//
268
345
for (const algo of [' dsa' , ' rsa' , ' ecdsa' , ' ed25519' ]) {
0 commit comments