PeculiarVentures / x509

@peculiar/x509 is an easy to use TypeScript/Javascript library based on @peculiar/asn1-schema that makes generating X.509 Certificates and Certificate Requests as well as validating certificate chains easy
https://peculiarventures.github.io/x509/
MIT License
86 stars 14 forks source link

Find extension by OID/type #32

Closed cereblanco closed 2 years ago

cereblanco commented 2 years ago

Hello! Thank you for this library. 🙇🏼‍♀️

Do we have support for finding a certificate extension given a oid (in the case of Extension class, that would be type)? I would like to create a util for it if it does not exist yet. Thank you

rmhrisk commented 2 years ago

Not without an enumeration of extensions

microshine commented 2 years ago

https://peculiarventures.github.io/x509/classes/X509Certificate.html

The current API implements getExtension and getExtensions methods. These methods allow getting Extension by OID or Extension class

// get by OID
cert.getExtension("2.5.29.15");

// get by class
cert.getExtensions(x509.KeyUsagesExtension)

see tests

cereblanco commented 2 years ago

Exactly what i needed. Thank you!

Closing this issue now.