Changeset 35918 in project


Ignore:
Timestamp:
07/15/18 22:09:40 (14 months ago)
Author:
Kon Lovett
Message:

uses 4.1 prim, more arg checks, add test

Location:
release/5/message-digest-type/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/message-digest-type/trunk/message-digest-type.egg

    r35890 r35918  
    33
    44((synopsis "Message Digest Type")
    5  (version "4.0.0")
     5 (version "4.0.1")
    66 (category crypt)
    77 (author "[[Kon Lovett|kon lovett]]")
     
    1010        (check-errors "3.1.0")
    1111        (blob-utils "2.0.0")
    12         (string-utils "2.0.4"))
     12        (string-utils "2.0.4")
     13        (message-digest-primitive "4.1.0"))
    1314 (test-dependencies test)
    1415 (components
  • release/5/message-digest-type/trunk/message-digest-type.scm

    r35890 r35918  
    3434  (only blob-hexadecimal blob->hex)
    3535  (only string-hexadecimal string->hex)
    36   (only type-checks define-check+error-type)
     36  (only type-checks define-check+error-type check-positive-fixnum)
    3737  (only type-errors error-argument-type)
    3838  message-digest-primitive)
     
    154154(: message-digest-context (message-digest -> message-digest-context))
    155155(: message-digest-buffer (message-digest -> (or boolean message-digest-buffer)))
     156(: message-digest-buffer-set! (message-digest (or boolean message-digest-buffer) -> void))
    156157;
    157158(define-record-type message-digest
     
    178179(define (ensure-message-digest-buffer! md siz)
    179180  (let (
    180     (buf (message-digest-buffer md))
    181     (siz (fxmax siz MINIMUM-BUFFER-SIZE)) )
     181    (buf
     182      (message-digest-buffer (check-message-digest 'ensure-message-digest-buffer! md)))
     183    (siz
     184      (fxmax
     185        (check-positive-fixnum 'ensure-message-digest-buffer! siz)
     186        MINIMUM-BUFFER-SIZE)) )
    182187    ;enough space? then reuse, otherwise new buffer
    183188    (if (and buf (fx<= siz (number-of-bytes buf)))
     
    191196(define (initialize-message-digest mdp)
    192197  (let (
    193     (ctx
    194       (make-message-digest-primitive-context
    195         (check-message-digest-primitive 'initialize-message-digest mdp))))
     198    (ctx (make-message-digest-primitive-context mdp)) )
    196199    ((message-digest-primitive-init mdp) ctx)
    197200    (*make-message-digest mdp ctx #f) ) )
  • release/5/message-digest-type/trunk/tests/message-digest-type-test.scm

    r35913 r35918  
    99;;;
    1010
    11 (import message-digest-type message-digest-primitive)
     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)
    1259
    1360;;;
Note: See TracChangeset for help on using the changeset viewer.