subtle_dsa.js 890 B

1234567891011121314151617181920212223242526
  1. import { JOSENotSupported } from '../util/errors.js';
  2. export default function subtleDsa(alg, algorithm) {
  3. const hash = `SHA-${alg.slice(-3)}`;
  4. switch (alg) {
  5. case 'HS256':
  6. case 'HS384':
  7. case 'HS512':
  8. return { hash, name: 'HMAC' };
  9. case 'PS256':
  10. case 'PS384':
  11. case 'PS512':
  12. return { hash, name: 'RSA-PSS', saltLength: alg.slice(-3) >> 3 };
  13. case 'RS256':
  14. case 'RS384':
  15. case 'RS512':
  16. return { hash, name: 'RSASSA-PKCS1-v1_5' };
  17. case 'ES256':
  18. case 'ES384':
  19. case 'ES512':
  20. return { hash, name: 'ECDSA', namedCurve: algorithm.namedCurve };
  21. case 'EdDSA':
  22. return { name: algorithm.name };
  23. default:
  24. throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
  25. }
  26. }