policy.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 objs = require('./objs');
  11. // The default policy is created with a null prototype and then frozen, so that
  12. // it cannot be manipulated (accidentally or otherwise).
  13. var defaultPolicy_ = require('./default-policy.json');
  14. defaultPolicy_ = objs.freeze(objs.leanCopy(defaultPolicy_));
  15. module.exports = CryptographicPolicy;
  16. /**
  17. * @class CryptographicPolicy
  18. * @classdesc The cryptographic policy API. To instantiate this object, use the
  19. * method {@link newInstance}.
  20. * @hideconstructor
  21. * @param {Object}
  22. * [policy=Default policy] The cryptographic policy to use, as a JSON
  23. * object.
  24. */
  25. function CryptographicPolicy(policy) {
  26. // Get a fresh copy of the default policy.
  27. objs.leanCopy(defaultPolicy_, this);
  28. // If there is a policy as a constructor argument, merge it with the default
  29. // policy. But first make sure the object is lean.
  30. if (typeof policy === 'object') {
  31. policy = objs.leanCopy(policy);
  32. objs.leanCopy(objs.merge(this, policy), this);
  33. }
  34. }