md5_spec.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. local md5 = require('md5')
  2. local function hex2bin(hex)
  3. local result, _ = hex:gsub('..', function(hexval)
  4. return string.char(tonumber(hexval, 16))
  5. end)
  6. return result
  7. end
  8. describe('md5', function()
  9. describe('md5.sumhexa', function()
  10. it('works', function()
  11. assert.equal(md5.sumhexa("asdf"), '912ec803b2ce49e4a541068d495ab570')
  12. assert.equal(md5.sumhexa('The quick brown fox jumps over the lazy dog'), '9e107d9d372bb6826bd81d3542a419d6')
  13. assert.equal(md5.sumhexa('The quick brown fox jumps over the lazy dog.'), 'e4d909c290d0fb1ca068ffaddf22cbd0')
  14. assert.equal(md5.sumhexa(''), 'd41d8cd98f00b204e9800998ecf8427e')
  15. assert.equal(md5.sumhexa(('1'):rep(824)), 'a126fd3611ab8d9b7e8a3384e2fa78a0')
  16. assert.equal(md5.sumhexa(('1'):rep(1528)), '3750b6a29d923b633e05d6ae76895664')
  17. end)
  18. end)
  19. describe('md5.sum', function()
  20. it('works', function()
  21. assert.equal(md5.sum("asdf"), hex2bin '912ec803b2ce49e4a541068d495ab570')
  22. assert.equal(md5.sum('The quick brown fox jumps over the lazy dog'), hex2bin '9e107d9d372bb6826bd81d3542a419d6')
  23. assert.equal(md5.sum('The quick brown fox jumps over the lazy dog.'), hex2bin 'e4d909c290d0fb1ca068ffaddf22cbd0')
  24. assert.equal(md5.sum(''), hex2bin 'd41d8cd98f00b204e9800998ecf8427e')
  25. assert.equal(md5.sum(('1'):rep(824)), hex2bin 'a126fd3611ab8d9b7e8a3384e2fa78a0')
  26. assert.equal(md5.sum(('1'):rep(1528)), hex2bin '3750b6a29d923b633e05d6ae76895664')
  27. end)
  28. end)
  29. end)