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
78 stars 10 forks source link

`RsaAlgorithm.toAsnAlgorithm` throws error for string type `hash` algorithm #61

Closed microshine closed 10 months ago

microshine commented 10 months ago

Describe the bug: The method RsaAlgorithm.toAsnAlgorithm in rsa_algorithm.ts throws an error when the hash property in the algorithm object is a string, rather than an AlgorithmIdentifier.

To Reproduce:

  1. Set the algorithm object as:
    const algorithm = {
    name: "RSASSA-PKCS1-v1_5",
    hash: "SHA-256",
    };
  2. Use the RsaAlgorithm.toAsnAlgorithm method.
  3. An error is thrown.

Expected behavior: The method should handle string values for hash.

Reference: https://github.com/PeculiarVentures/x509/blob/ebbefa71161d00b79bdafa526b60eeea4f9f568e/src/rsa_algorithm.ts#L17

Additional context: Allowing string types for the hash property could improve the user experience and reduce confusion.