validation-data.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 mathematical = require('../../lib/index');
  11. var CommonTestData = require('./common-data');
  12. var secureRandom = require('scytl-securerandom');
  13. var forge = require('node-forge');
  14. module.exports = ValidationTestData;
  15. var BigInteger = forge.jsbn.BigInteger;
  16. /**
  17. * Provides the input validation data needed by the mathematical service unit
  18. * tests.
  19. */
  20. function ValidationTestData() {
  21. var commonTestData = new CommonTestData();
  22. var p = commonTestData.getP();
  23. var minCertaintyLevel = commonTestData.getMinimumCertaintyLevel();
  24. var multiGroupElementValues = commonTestData.multiGroupElementValues();
  25. var nonObject_ = 999;
  26. var emptyObject_ = {};
  27. var nonSecureRandomService_ = mathematical.newService();
  28. var nonBoolean_ = '';
  29. var nonNumber_ = '';
  30. var nonPositiveNumber_ = 0;
  31. var nonString_ = 0;
  32. var nonJsonString_ = 'Not a JSON string';
  33. var nonArray_ = '';
  34. var nonMathObject_ = secureRandom.newService();
  35. var nonMathObjectArray_ = [];
  36. nonMathObjectArray_.push(nonMathObject_ + '1');
  37. nonMathObjectArray_.push(nonMathObject_ + '2');
  38. nonMathObjectArray_.push(nonMathObject_ + '3');
  39. var tooSmallModulus_ = new BigInteger('2');
  40. var tooSmallOrder_ = BigInteger.ZERO;
  41. var tooLargeOrder_ = p;
  42. var tooSmallGenerator_ = BigInteger.ONE;
  43. var tooLargeGenerator_ = p;
  44. var tooSmallElementValue_ = BigInteger.ZERO;
  45. var tooLargeElementValue_ = p;
  46. var tooSmallPBitLength_ = 1;
  47. var tooLowCertaintyLevel_ = minCertaintyLevel - 1;
  48. var tooLargeNumMembersRequired_ = multiGroupElementValues.length + 1;
  49. this.getNonObject = function() {
  50. return nonObject_;
  51. };
  52. this.getEmptyObject = function() {
  53. return emptyObject_;
  54. };
  55. this.getNonSecureRandomService = function() {
  56. return nonSecureRandomService_;
  57. };
  58. this.getNonBoolean = function() {
  59. return nonBoolean_;
  60. };
  61. this.getNonNumber = function() {
  62. return nonNumber_;
  63. };
  64. this.getNonPositiveNumber = function() {
  65. return nonPositiveNumber_;
  66. };
  67. this.getNonString = function() {
  68. return nonString_;
  69. };
  70. this.getNonJsonString = function() {
  71. return nonJsonString_;
  72. };
  73. this.getNonArray = function() {
  74. return nonArray_;
  75. };
  76. this.getNonMathObject = function() {
  77. return nonMathObject_;
  78. };
  79. this.getNonMathObjectArray = function() {
  80. return nonMathObjectArray_;
  81. };
  82. this.getTooSmallModulus = function() {
  83. return tooSmallModulus_;
  84. };
  85. this.getTooSmallOrder = function() {
  86. return tooSmallOrder_;
  87. };
  88. this.getTooLargeOrder = function() {
  89. return tooLargeOrder_;
  90. };
  91. this.getTooSmallGenerator = function() {
  92. return tooSmallGenerator_;
  93. };
  94. this.getTooLargeGenerator = function() {
  95. return tooLargeGenerator_;
  96. };
  97. this.getTooSmallElementValue = function() {
  98. return tooSmallElementValue_;
  99. };
  100. this.getTooLargeElementValue = function() {
  101. return tooLargeElementValue_;
  102. };
  103. this.getTooSmallModulusBitLength = function() {
  104. return tooSmallPBitLength_;
  105. };
  106. this.getTooLowCertaintyLevel = function() {
  107. return tooLowCertaintyLevel_;
  108. };
  109. this.getTooLargeNumMembersRequired = function() {
  110. return tooLargeNumMembersRequired_;
  111. };
  112. }