source: project/release/5/message-digest-type/tags/4.0.1/tests/message-digest-type-test.scm @ 35919

Last change on this file since 35919 was 35919, checked in by Kon Lovett, 21 months ago

rel 4.0.1

File size: 1.6 KB
Line 
1;;;; message-digest-type-test.scm  -*- Scheme -*-
2;;;; Kon Lovett, Jul '18
3;;;; Kon Lovett, Oct '17
4
5(import test)
6
7(test-begin "Message Digest Type")
8
9;;;
10
11(import
12  (chicken blob)
13  (chicken memory)
14  ;(chicken format)
15  message-digest-type message-digest-primitive)
16
17(define-constant DIGEST-LENGTH 5)
18(define-constant CONTEXT-SIZE 10)
19
20(let ()
21
22        (define the-ctx #f)
23
24  (define (make-context)
25    ;Init to 0 necessary since DIGEST-LENGTH is possibly > than
26    ;the input size! (Actually just needs to be a known value,
27    ;`(integer->char #xff)' would work as well.)
28    (string->blob (make-string CONTEXT-SIZE #\nul)) )
29
30  (define (init ctx)
31    (set! the-ctx ctx) )
32
33  (define (update ctx bytes count)
34    ;(printf "Update Ctx: ~S Bytes: ~S Count: ~S~%" ctx bytes count) (flush-output)
35    (assert (eq? ctx the-ctx))
36    (assert (not (not bytes)))
37    (assert (< 0 count))
38    (assert (<= count CONTEXT-SIZE))  ; So no mem overflow
39    (assert (blob? ctx))
40    (move-memory! bytes ctx count) )
41
42  (define (final ctx result)
43    ;(printf "Final Result Size: ~S Ctx: ~S Result: ~S~%" (blob-size result) ctx result) (flush-output)
44    (assert (eq? ctx the-ctx))
45    (assert (not (not result)))
46    (assert (blob? ctx))
47    (assert (<= (blob-size result) DIGEST-LENGTH))  ; So no mem overflow
48    (move-memory! ctx result DIGEST-LENGTH) )
49
50  (define mdp (make-message-digest-primitive make-context DIGEST-LENGTH init update final))
51
52  (test-group "init & final"
53    (let (
54      (md (initialize-message-digest mdp)) )
55      (test-assert (message-digest? md))
56      (test "0000000000" (finalize-message-digest md)) )
57  )
58)
59
60;;;
61
62(test-end "Message Digest Type")
63
64(test-exit)
Note: See TracBrowser for help on using the repository browser.