2
0

index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 */
  9. 'use strict';
  10. var PbkdfService = require('./service');
  11. var validator = require('./input-validator');
  12. module.exports = {
  13. /**
  14. * Creates a new PbkdfService object, which encapsulates a PBKDF service.
  15. *
  16. * @function newService
  17. * @global
  18. * @param {Object}
  19. * [options] An object containing optional arguments.
  20. * @param {Policy}
  21. * [options.policy=Default policy] The cryptographic policy to
  22. * use.
  23. * @returns {PbkdfService} The new PbkdfService object.
  24. * @throws {Error}
  25. * If the input data validation fails.
  26. * @example <caption> How to use a cryptographic policy that sets the PBKDF
  27. * derivation key length to 16 bytes</code></caption>
  28. *
  29. * var cryptoPolicy = require('scytl-cryptopolicy');
  30. * var pbkdf = require('scytl-pbkdf');
  31. *
  32. * var myPolicy = cryptoPolicy.newInstance();
  33. *
  34. * myPolicy.primitives.keyDerivation.pbkdf.keyLengthBytes =
  35. * cryptoPolicy.options.primitives.keyDerivation.pbkdf.keyLengthBytes.KL_16;
  36. *
  37. * var pbkdfService = pbkdf.newService({policy: myPolicy});
  38. */
  39. newService: function(options) {
  40. checkData(options);
  41. return new PbkdfService(options);
  42. }
  43. };
  44. function checkData(options) {
  45. options = options || {};
  46. if (typeof options.policy !== 'undefined') {
  47. validator.checkIsObjectWithProperties(
  48. options.policy, 'Cryptographic policy provided to PBKDF service');
  49. }
  50. }