Skip to content

Commit

Permalink
Fix certificate name
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-slobodian committed Oct 11, 2024
1 parent 050fd8a commit a48b15e
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/utils/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,22 @@ export function getCertificateName(certificate: CertificateProps) {
if (!certificate.subject) {
return certificate.subjectName;
}
const subject = Object.fromEntries(
Object.entries(certificate.subject).map(([key, value]) => [
key,
Array.isArray(value) ? value[0] : value, // Take the first element if value is an array
])
);
const { G, CN, SN, E } = subject;

const { G, CN, SN, E } = certificate.subject;

// Return Common Name if present.
if (CN) {
return CN;
return CN[0];
}

// Return Given Name + Surname if both present.
if (G && SN) {
return `${G} ${SN}`;
return `${G[0]} ${SN[0]}`;
}

// Return Email if none of the above present
if (E) {
return E;
return E[0];
}

return certificate.subjectName;
Expand Down

0 comments on commit a48b15e

Please sign in to comment.