test_crypto_constants.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * Created by bmf on 10/31/13.
  3. */
  4. "use strict";
  5. var assert = require('assert');
  6. var sodium = require('../build/Release/sodium');
  7. function checkBiggerThanZero(n) {
  8. assert.equal(typeof n, 'number');
  9. assert.ok(n > 0);
  10. }
  11. describe('Constants', function() {
  12. it('should define lib constants', function(done) {
  13. checkBiggerThanZero(sodium.crypto_auth_BYTES);
  14. checkBiggerThanZero(sodium.crypto_auth_KEYBYTES);
  15. checkBiggerThanZero(sodium.crypto_box_NONCEBYTES);
  16. checkBiggerThanZero(sodium.crypto_box_BEFORENMBYTES);
  17. checkBiggerThanZero(sodium.crypto_box_BOXZEROBYTES);
  18. checkBiggerThanZero(sodium.crypto_box_PUBLICKEYBYTES);
  19. checkBiggerThanZero(sodium.crypto_box_SECRETKEYBYTES);
  20. checkBiggerThanZero(sodium.crypto_box_ZEROBYTES);
  21. checkBiggerThanZero(sodium.crypto_hash_BYTES);
  22. checkBiggerThanZero(sodium.crypto_onetimeauth_BYTES);
  23. checkBiggerThanZero(sodium.crypto_onetimeauth_KEYBYTES);
  24. checkBiggerThanZero(sodium.crypto_secretbox_BOXZEROBYTES);
  25. checkBiggerThanZero(sodium.crypto_secretbox_KEYBYTES);
  26. checkBiggerThanZero(sodium.crypto_secretbox_NONCEBYTES);
  27. checkBiggerThanZero(sodium.crypto_secretbox_ZEROBYTES);
  28. checkBiggerThanZero(sodium.crypto_sign_BYTES);
  29. checkBiggerThanZero(sodium.crypto_sign_PUBLICKEYBYTES);
  30. checkBiggerThanZero(sodium.crypto_sign_SECRETKEYBYTES);
  31. checkBiggerThanZero(sodium.crypto_stream_KEYBYTES);
  32. checkBiggerThanZero(sodium.crypto_stream_NONCEBYTES);
  33. done();
  34. });
  35. it('should fail to assign crypto_stream_NONCEBYTES', function(done) {
  36. assert.throws(function() {
  37. sodium.crypto_stream_NONCEBYTES = 0;
  38. });
  39. done();
  40. });
  41. it('should fail to assign crypto_stream_KEYBYTES', function(done) {
  42. assert.throws(function() {
  43. sodium.crypto_stream_KEYBYTES = 0;
  44. });
  45. done();
  46. });
  47. it('should fail to assign crypto_sign_SECRETKEYBYTES', function(done) {
  48. assert.throws(function() {
  49. sodium.crypto_sign_SECRETKEYBYTES = 0;
  50. });
  51. done();
  52. });
  53. it('should fail to assign crypto_sign_PUBLICKEYBYTES', function(done) {
  54. assert.throws(function() {
  55. sodium.crypto_sign_PUBLICKEYBYTES = 0;
  56. });
  57. done();
  58. });
  59. it('should fail to assign crypto_sign_BYTES', function(done) {
  60. assert.throws(function() {
  61. sodium.crypto_sign_BYTES = 0;
  62. });
  63. done();
  64. });
  65. it('should fail to assign crypto_secretbox_ZEROBYTES', function(done) {
  66. assert.throws(function() {
  67. sodium.crypto_secretbox_ZEROBYTES = 0;
  68. });
  69. done();
  70. });
  71. it('should fail to assign crypto_secretbox_NONCEBYTES', function(done) {
  72. assert.throws(function() {
  73. sodium.crypto_secretbox_NONCEBYTES = 0;
  74. });
  75. done();
  76. });
  77. it('should fail to assign crypto_secretbox_KEYBYTES', function(done) {
  78. assert.throws(function() {
  79. sodium.crypto_secretbox_KEYBYTES = 0;
  80. });
  81. done();
  82. });
  83. it('should fail to assign crypto_onetimeauth_KEYBYTES', function(done) {
  84. assert.throws(function() {
  85. sodium.crypto_onetimeauth_KEYBYTES = 0;
  86. });
  87. done();
  88. });
  89. it('should fail to assign crypto_secretbox_BOXZEROBYTES', function(done) {
  90. assert.throws(function() {
  91. sodium.crypto_secretbox_BOXZEROBYTES = 0;
  92. });
  93. done();
  94. });
  95. it('should fail to assign crypto_onetimeauth_BYTES', function(done) {
  96. assert.throws(function() {
  97. sodium.crypto_onetimeauth_BYTES = 0;
  98. });
  99. done();
  100. });
  101. it('should fail to assign crypto_hash_BYTES', function(done) {
  102. assert.throws(function() {
  103. sodium.crypto_hash_BYTES = 0;
  104. });
  105. done();
  106. });
  107. it('should fail to assign crypto_box_ZEROBYTES', function(done) {
  108. assert.throws(function() {
  109. sodium.crypto_box_ZEROBYTES = 0;
  110. });
  111. done();
  112. });
  113. it('should fail to assign crypto_box_SECRETKEYBYTES', function(done) {
  114. assert.throws(function() {
  115. sodium.crypto_box_SECRETKEYBYTES = 0;
  116. });
  117. done();
  118. });
  119. it('should fail to assign crypto_box_PUBLICKEYBYTES', function(done) {
  120. assert.throws(function() {
  121. sodium.crypto_box_PUBLICKEYBYTES = 0;
  122. });
  123. done();
  124. });
  125. it('should fail to assign crypto_box_BOXZEROBYTES', function(done) {
  126. assert.throws(function() {
  127. sodium.crypto_box_BOXZEROBYTES = 0;
  128. });
  129. done();
  130. });
  131. it('should fail to assign crypto_box_BEFORENMBYTES', function(done) {
  132. assert.throws(function() {
  133. sodium.crypto_box_BEFORENMBYTES = 0;
  134. });
  135. done();
  136. });
  137. it('should fail to assign crypto_auth_KEYBYTES', function(done) {
  138. assert.throws(function() {
  139. sodium.crypto_auth_KEYBYTES = 0;
  140. });
  141. done();
  142. });
  143. it('should fail to assign crypto_box_NONCEBYTES', function(done) {
  144. assert.throws(function() {
  145. sodium.crypto_box_NONCEBYTES = 0;
  146. });
  147. done();
  148. });
  149. it('should fail to assign crypto_auth_BYTES', function(done) {
  150. assert.throws(function() {
  151. sodium.crypto_auth_BYTES = 0;
  152. });
  153. done();
  154. });
  155. });