service.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 X509Certificate = require('./x509-certificate');
  11. var CertificateValidator = require('./certificate-validator');
  12. var validator = require('./input-validator');
  13. module.exports = CertificateService;
  14. /**
  15. * @class CertificateService
  16. * @classdesc The certificate service API. To instantiate this object, use the
  17. * method {@link newService}.
  18. * @hideconstructor
  19. */
  20. function CertificateService() {}
  21. CertificateService.prototype = {
  22. /**
  23. * Creates a new X509Certificate object and loads it with the provided X.509
  24. * certificate.
  25. *
  26. * @function newX509Certificate
  27. * @memberof CertificateService
  28. * @param {string}
  29. * certificate The provided X.509 certificate, in PEM format.
  30. * @returns {X509Certificate} The X509Certificate object.
  31. * @throws {Error}
  32. * If the input data validation fails.
  33. */
  34. newX509Certificate: function(certificate) {
  35. validator.checkIsNonEmptyString(
  36. certificate, 'X.509 certificate in PEM format');
  37. return new X509Certificate(certificate);
  38. },
  39. /**
  40. * Creates a new CertificateValidator object for validating individual
  41. * certificates or certificate chains.
  42. *
  43. * @function newValidator
  44. * @memberof CertificateService
  45. * @returns {CertificateValidator} The CertificateValidator object.
  46. */
  47. newValidator: function() {
  48. return new CertificateValidator();
  49. }
  50. };