md5_spec.lua 1.3 KB

12345678910111213141516171819202122232425262728293031
  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. end)
  17. end)
  18. describe('md5.sum', function()
  19. it('works', function()
  20. assert.equal(md5.sum("asdf"), hex2bin '912ec803b2ce49e4a541068d495ab570')
  21. assert.equal(md5.sum('The quick brown fox jumps over the lazy dog'), hex2bin'9e107d9d372bb6826bd81d3542a419d6')
  22. assert.equal(md5.sum('The quick brown fox jumps over the lazy dog.'), hex2bin'e4d909c290d0fb1ca068ffaddf22cbd0')
  23. assert.equal(md5.sum(''), hex2bin'd41d8cd98f00b204e9800998ecf8427e')
  24. assert.equal(md5.sum(('1'):rep(824)), hex2bin'a126fd3611ab8d9b7e8a3384e2fa78a0')
  25. end)
  26. end)
  27. end)