service.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Pkcs12KeyStore = require('./pkcs12-keystore');
  11. var ScytlKeyStore = require('./scytl-keystore');
  12. module.exports = KeyStoreService;
  13. /**
  14. * @class KeyStoreService
  15. * @classdesc The key store service API. To instantiate this object, use the
  16. * method {@link newService}.
  17. * @hideconstructor
  18. * @param {Object}
  19. * [options] An object containing optional arguments.
  20. * @param {Policy}
  21. * [options.policy=Default policy] The cryptographic policy to use.
  22. * @param {PbkdfRandomService}
  23. * [options.pbkdfRandomService=Created internally] The PBKDF service
  24. * to use.
  25. * @param {SymmetricCryptographyService}
  26. * [options.symmetricCryptographyService=Created internally] The
  27. * symmetric cryptography service to use.
  28. * @param {ElGamalCryptographyService}
  29. * [options.elGamalCryptographyService=Created internally] The
  30. * ElGamal cryptography service to use.
  31. */
  32. function KeyStoreService(options) {
  33. /**
  34. * Creates a new Pkcs12KeyStore object and loads it with the provided PKCS
  35. * #12 key store.
  36. *
  37. * @function newPkcs12KeyStore
  38. * @memberof KeyStoreService
  39. * @param {Uint8Array|string}
  40. * keyStore The provided PKCS #12 key store, as a DER encoded
  41. * ASN.1 structure <b>OR</b> such a structure Base64 encoded.
  42. * @param {string}
  43. * password The password to load the PKCS #12 key store.
  44. * @returns {Pkcs12KeyStore} The Pkcs12KeyStore object.
  45. * @throws {Error}
  46. * If the input data validation fails or the PKCS #12 key store
  47. * could not be loaded.
  48. */
  49. this.newPkcs12KeyStore = function(keyStore, password) {
  50. return new Pkcs12KeyStore(keyStore, password);
  51. };
  52. /**
  53. * Creates a new ScytlKeyStore object and loads it with the provided Scytl
  54. * key store.
  55. *
  56. * @function newScytlKeyStore
  57. * @memberof KeyStoreService
  58. * @param {Object|string}
  59. * keyStore The provided Scytl key store, as an object with
  60. * expected properties <b>OR</b> its JSON string representation.
  61. * @param {string}
  62. * password The password to load the Scytl key store.
  63. * @returns {ScytlKeyStore} The ScytlKeyStore object.
  64. * @throws {Error}
  65. * If the input data validation fails or the Scytl key store
  66. * could not be loaded.
  67. */
  68. this.newScytlKeyStore = function(keyStore, password) {
  69. return new ScytlKeyStore(keyStore, password, options);
  70. };
  71. }