;;;; message-digest-type-test.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 ;;;; Kon Lovett, Oct '17 (import test) (test-begin "Message Digest Type") ;;; (import scheme) (import (chicken blob)) (import (chicken memory)) ;(import (chicken format)) (import message-digest-type) (import message-digest-primitive) (define-constant DIGEST-LENGTH 5) (define-constant CONTEXT-SIZE 10) (let () (define the-ctx #f) (define (make-context) ;Init to 0 necessary since DIGEST-LENGTH is possibly > than ;the input size! (Actually just needs to be a known value, ;`(integer->char #xff)' would work as well.) (string->blob (make-string CONTEXT-SIZE #\nul)) ) (define (init ctx) (set! the-ctx ctx) ) (define (update ctx bytes count) ;(printf "Update Ctx: ~S Bytes: ~S Count: ~S~%" ctx bytes count) (flush-output) (assert (eq? ctx the-ctx)) (assert (not (not bytes))) (assert (< 0 count)) (assert (<= count CONTEXT-SIZE)) ; So no mem overflow (assert (blob? ctx)) (move-memory! bytes ctx count) ) (define (final ctx result) ;(printf "Final Result Size: ~S Ctx: ~S Result: ~S~%" (blob-size result) ctx result) (flush-output) (assert (eq? ctx the-ctx)) (assert (not (not result))) (assert (blob? ctx)) (assert (<= (blob-size result) DIGEST-LENGTH)) ; So no mem overflow (move-memory! ctx result DIGEST-LENGTH) ) (define mdp (make-message-digest-primitive make-context DIGEST-LENGTH init update final)) (test-group "init & final" (let ( (md (initialize-message-digest mdp)) ) (test-assert (message-digest? md)) (test "0000000000" (finalize-message-digest md)) ) ) ) ;;; (test-end "Message Digest Type") (test-exit)