2
0

prng.spec.js 967 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true, jasmine: true */
  9. 'use strict';
  10. var Prng = require('../lib/prng.js');
  11. var codec = require('scytl-codec');
  12. describe('The pseudo-random number generator should be able to ..', function() {
  13. it('generate pseudo-random numbers', function() {
  14. var prng = new Prng(codec.utf8Encode('123abc'));
  15. // Generate a 4-byte random number.
  16. var byteArray = prng.nextBytes(4);
  17. expect(byteArray).toBeDefined();
  18. expect(byteArray.length).toBe(4);
  19. });
  20. it('enforce a minimum length', function() {
  21. var prng = new Prng('123abc');
  22. expect(function() {
  23. prng.nextBytes();
  24. }).toThrow();
  25. expect(function() {
  26. prng.nextBytes(0);
  27. }).toThrow();
  28. expect(function() {
  29. prng.nextBytes(1);
  30. }).toBeDefined();
  31. });
  32. });