cek.js 602 B

1234567891011121314151617181920
  1. import { JOSENotSupported } from '../util/errors.js';
  2. import random from '../runtime/random.js';
  3. export function bitLength(alg) {
  4. switch (alg) {
  5. case 'A128GCM':
  6. return 128;
  7. case 'A192GCM':
  8. return 192;
  9. case 'A256GCM':
  10. case 'A128CBC-HS256':
  11. return 256;
  12. case 'A192CBC-HS384':
  13. return 384;
  14. case 'A256CBC-HS512':
  15. return 512;
  16. default:
  17. throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
  18. }
  19. }
  20. export default (alg) => random(new Uint8Array(bitLength(alg) >> 3));