a zip code crypto-currency system good for red ONLY

index.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. var test = require('tape')
  2. var fs = require('fs')
  3. var parseKey = require('../')
  4. var rsa1024 = {
  5. private: fs.readFileSync(__dirname + '/rsa.1024.priv'),
  6. public: fs.readFileSync(__dirname + '/rsa.1024.pub')
  7. }
  8. var rsa2028 = {
  9. private: fs.readFileSync(__dirname + '/rsa.2028.priv'),
  10. public: fs.readFileSync(__dirname + '/rsa.2028.pub')
  11. }
  12. var nonrsa1024 = {
  13. private: fs.readFileSync(__dirname + '/1024.priv'),
  14. public: fs.readFileSync(__dirname + '/1024.pub')
  15. }
  16. var pass1024 = {
  17. private: {
  18. passphrase: 'fooo',
  19. key: fs.readFileSync(__dirname + '/pass.1024.priv')
  20. },
  21. public: fs.readFileSync(__dirname + '/pass.1024.pub')
  22. }
  23. var ec = {
  24. private: fs.readFileSync(__dirname + '/ec.priv'),
  25. public: fs.readFileSync(__dirname + '/ec.pub')
  26. }
  27. var ecpass = {
  28. private: {
  29. key: fs.readFileSync(__dirname + '/ec.pass.priv'),
  30. passphrase: 'bard'
  31. },
  32. public: fs.readFileSync(__dirname + '/ec.pub')
  33. }
  34. var dsa = {
  35. private: fs.readFileSync(__dirname + '/dsa.1024.priv'),
  36. public: fs.readFileSync(__dirname + '/dsa.1024.pub')
  37. }
  38. var dsa2 = {
  39. private: fs.readFileSync(__dirname + '/dsa.2048.priv'),
  40. public: fs.readFileSync(__dirname + '/dsa.2048.pub')
  41. }
  42. var dsapass = {
  43. private: {
  44. key: fs.readFileSync(__dirname + '/pass.dsa.1024.priv'),
  45. passphrase: 'password'
  46. },
  47. public: fs.readFileSync(__dirname + '/pass.dsa.1024.pub')
  48. }
  49. var dsapass2 = {
  50. private: {
  51. key: fs.readFileSync(__dirname + '/pass2.dsa.1024.priv'),
  52. passphrase: 'password'
  53. },
  54. public: fs.readFileSync(__dirname + '/pass2.dsa.1024.pub')
  55. }
  56. var rsapass = {
  57. private: {
  58. key: fs.readFileSync(__dirname + '/pass.rsa.1024.priv'),
  59. passphrase: 'password'
  60. },
  61. public: fs.readFileSync(__dirname + '/pass.rsa.1024.pub')
  62. }
  63. var rsapass2 = {
  64. private: {
  65. key: fs.readFileSync(__dirname + '/pass.rsa.2028.priv'),
  66. passphrase: 'password'
  67. },
  68. public: fs.readFileSync(__dirname + '/pass.rsa.2028.pub')
  69. }
  70. var cert = {
  71. private: fs.readFileSync(__dirname + '/rsa.1024.priv'),
  72. public: fs.readFileSync(__dirname + '/node.cert')
  73. }
  74. var i = 0
  75. function testIt (keys) {
  76. test('key ' + (++i), function (t) {
  77. t.plan(2)
  78. t.ok(parseKey(keys.public), 'public key')
  79. t.ok(parseKey(keys.private), 'private key')
  80. })
  81. }
  82. function testEOL (keys) {
  83. var publicKey = keys.public.toString()
  84. var newLineRegex = /\r?\n/g
  85. var genPrivate = function (replace) {
  86. if (keys.private.key) {
  87. return { key: keys.private.key.toString().replace(newLineRegex, replace), passphrase: keys.private.passphrase }
  88. } else {
  89. return keys.private.toString().replace(newLineRegex, replace)
  90. }
  91. }
  92. var testN = {
  93. private: genPrivate('\n'),
  94. public: publicKey.replace(newLineRegex, '\n')
  95. }
  96. testIt(testN)
  97. var testR = {
  98. private: genPrivate('\r'),
  99. public: publicKey.replace(newLineRegex, '\r')
  100. }
  101. testIt(testR)
  102. var testRN = {
  103. private: genPrivate('\r\n'),
  104. public: publicKey.replace(newLineRegex, '\r\n')
  105. }
  106. testIt(testRN)
  107. }
  108. testIt(dsa)
  109. testIt(dsa2)
  110. testIt(rsa1024)
  111. testIt(ec)
  112. testIt(rsa2028)
  113. testIt(nonrsa1024)
  114. testIt(ecpass)
  115. testIt(dsapass)
  116. testIt(dsapass2)
  117. testIt(rsapass)
  118. testIt(rsapass2)
  119. testIt(pass1024)
  120. testIt(pass1024)
  121. testIt(cert)
  122. testEOL(dsa)
  123. testEOL(dsa2)
  124. testEOL(rsa1024)
  125. testEOL(ec)
  126. testEOL(rsa2028)
  127. testEOL(nonrsa1024)
  128. testEOL(ecpass)
  129. testEOL(dsapass)
  130. testEOL(dsapass2)
  131. testEOL(rsapass)
  132. testEOL(rsapass2)
  133. testEOL(pass1024)
  134. testEOL(pass1024)
  135. testEOL(cert)