| 1 | // Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | import crypto.md5 |
| 5 | import hash |
| 6 | |
| 7 | // verify md5.Digest implements hash.Hash |
| 8 | fn test_digest_implements_hash() { |
| 9 | get_digest := fn () hash.Hash { |
| 10 | return md5.new() |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | fn test_crypto_md5() { |
| 15 | assert md5.sum('this is a md5 checksum.'.bytes()).hex() == '6fb421ff99036547655984da12973431' |
| 16 | } |
| 17 | |
| 18 | fn test_crypto_md5_writer() { |
| 19 | mut digest := md5.new() |
| 20 | digest.write('this is a'.bytes()) or { assert false } |
| 21 | digest.write(' md5 checksum.'.bytes()) or { assert false } |
| 22 | mut sum := digest.sum([]) |
| 23 | assert sum.hex() == '6fb421ff99036547655984da12973431' |
| 24 | sum = digest.sum([]) |
| 25 | assert sum.hex() == '6fb421ff99036547655984da12973431' |
| 26 | } |
| 27 | |
| 28 | fn test_crypto_md5_writer_reset() { |
| 29 | mut digest := md5.new() |
| 30 | digest.write('this is a'.bytes()) or { assert false } |
| 31 | digest.write(' md5 checksum.'.bytes()) or { assert false } |
| 32 | _ = digest.sum([]) |
| 33 | digest.reset() |
| 34 | digest.write('this is a'.bytes()) or { assert false } |
| 35 | digest.write(' md5 checksum.'.bytes()) or { assert false } |
| 36 | sum := digest.sum([]) |
| 37 | assert sum.hex() == '6fb421ff99036547655984da12973431' |
| 38 | } |
| 39 | |