summaryrefslogtreecommitdiff
path: root/src/components/SignaturesTableRows.astro
blob: eafd4de85e86e179d6ed8b1be6c54120258ba001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
import { type Summary, VerificationResult } from "@lib/pgp/summary";
import { PublicKey } from "openpgp";

type Props = { summary: Summary; rowspan?: number };

const { summary, rowspan } = Astro.props;
const [type, _, info] = summary;

let name: string = "";
let email: string = "";
let fingerprint: string = "";
let trust: number | undefined = NaN;
let commiter: boolean | undefined = undefined;
let revoked: boolean | undefined = undefined;
let keyType: "primary" | "sub" | "" = "";

switch (type) {
  case VerificationResult.MISSING_KEY:
    fingerprint = typeof info.keyID === "string"
      ? info.keyID
      : info.keyID.toHex();
    break;
  case VerificationResult.TRUSTED_KEY:
    const match = info.userID[0].match(/^(.*?)\s*(?:\((.*?)\))?\s*<(.+?)>$/);

    if (match) {
      name = match[1];
      email = match[3];
    }

    fingerprint = info.key.getFingerprint();
    trust = info.trust;
    keyType = info.key instanceof PublicKey ? "primary" : "sub";
    break;
}

const names = name.split(/\s/);
const firstName = names[0];
const lastName = names.length > 1 ? ` ${names[names.length - 1]}` : "";
---
<td {rowspan}><span title={name}>{firstName}{lastName}</span></td>
<td {rowspan}>{email}</td>
<td {rowspan}>
  <span title={fingerprint.replace(/(....)/g, "$1 ").trim()}>
    {`0x${fingerprint.slice(-8)}`}
  </span>
</td>
<td {rowspan}>{trust}</td>
<td {rowspan}>{commiter}</td>
<td {rowspan}>{revoked}</td>