Skip to content

Commit

Permalink
Fix get certificate subject
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-slobodian committed Oct 10, 2024
1 parent 3a37cb6 commit a8d7731
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/utils/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ export function certificateSubjectToString(
}

export function getCertificateSubject(subjectString: string) {
const name = new Name(subjectString).toJSON();
const obj = {} as CertificateSubjectProps;
if (name.length) {
for (const key in name[0]) {
obj[key as keyof CertificateSubjectProps] = Array.isArray(name[0][key])
? name[0][key][0]
: name[0][key];
}
}
return obj;
const jsonName = new Name(subjectString).toJSON();

return jsonName.reduce<Record<string, string[]>>((result, currentValue) => {
Object.keys(currentValue).forEach((keyName) => {
if (!result[keyName]) {
result[keyName] = currentValue[keyName];
} else {
result[keyName].push(...currentValue[keyName]);
}
});

return result;
}, {});
}

export function getCertificateName(certificate: CertificateProps) {
Expand Down

0 comments on commit a8d7731

Please sign in to comment.