PeculiarVentures / PKI.js

PKI.js is a pure JavaScript library implementing the formats that are used in PKI applications (signing, encryption, certificate requests, OCSP and TSP requests/responses). It is built on WebCrypto (Web Cryptography API) and requires no plug-ins.
http://pkijs.org
Other
1.3k stars 204 forks source link

Optimize and refactor formatPEM() function #277

Closed elias-pap closed 4 years ago

elias-pap commented 4 years ago

formatPEM() was duplicated 15 times in different forms in the examples. I moved it into common.js and optimized it. The attached benchmark shows ~4x speedup in Firefox and ~20x speedup in Chromium/Brave.

formatPEM_benchmark.txt

YuryStrozhevsky commented 4 years ago

@elias-pap The formatPEM function is not a part of library itself, it is a part of examples only. Be aware that examples don’t exist in a “production” version of PKIjs. So if you do want to optimise examples then make a “examples_common.js” under examples folder and put all common functions there, not in library code. The PKIjs doesn’t provide “formatting PEM” functionality, it is too trivial.

elias-pap commented 4 years ago

Should be done now.

YuryStrozhevsky commented 4 years ago

@elias-pap After your change command npm test is not working.

elias-pap commented 4 years ago

@elias-pap After your change command npm test is not working.

Fixed.