Changeset 40448 in project


Ignore:
Timestamp:
09/08/21 04:43:25 (3 weeks ago)
Author:
Kon Lovett
Message:

allow digest where primitive accepted (digest re-use possible)

Location:
release/5/message-digest-utils/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • release/5/message-digest-utils/trunk/message-digest-byte-vector.scm

    r40434 r40448  
    2121  message-digest-string!)
    2222
    23 (import scheme)
    24 (import (chicken base))
    25 (import (chicken blob))
    26 (import (chicken type))
    27 (import (only (srfi 13) substring/shared))
    28 (import (only type-checks check-blob check-string check-natural-fixnum check-range))
    29 (import message-digest-primitive)
    30 (import message-digest-type)
    31 (import message-digest-support)
     23(import scheme
     24  (chicken base)
     25  (chicken blob)
     26  (chicken type)
     27  (only (srfi 13) substring/shared)
     28  (only type-checks check-blob check-string check-natural-fixnum check-range)
     29  message-digest-primitive
     30  message-digest-type
     31  message-digest-support)
    3232
    3333;; Support
     
    3939(: message-digest-update-blob (message-digest blob #!optional fixnum fixnum -> void))
    4040(: message-digest-update-string (message-digest string #!optional fixnum fixnum -> void))
    41 (: message-digest-blob (message-digest-primitive blob #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
    42 (: message-digest-string (message-digest-primitive string #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
    43 (: message-digest-blob! (message-digest-primitive blob message-digest-buffer #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
    44 (: message-digest-string! (message-digest-primitive string message-digest-buffer #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
    45 ;
     41
     42(: message-digest-blob (message-digest-kind blob #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
     43(: message-digest-string (message-digest-kind string #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
     44
     45(: message-digest-blob! (message-digest-kind blob message-digest-buffer #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
     46(: message-digest-string! (message-digest-kind string message-digest-buffer #!optional message-digest-result-type fixnum fixnum -> message-digest-result-type))
    4647
    4748;;
     
    8788;; Single Source API
    8889
    89 (define (message-digest-blob mdp blb . opts)
     90(define (message-digest-blob mdk blb . opts)
    9091  (let-optionals* opts (
    9192    (restyp (message-digest-result-form))
     
    9394    (end (blob-size (check-blob 'message-digest-blob blb))) )
    9495    (let (
    95       (md (initialize-message-digest mdp)) )
     96      (md (initialized-message-digest mdk)) )
    9697      (check-fixnum-range 'message-digest-blob start end)
    9798      (message-digest-update-blob md blb start end)
    9899      (finalize-message-digest md restyp) ) ) )
    99100
    100 (define (message-digest-string mdp str . opts)
     101(define (message-digest-string mdk str . opts)
    101102  (let-optionals* opts (
    102103    (restyp (message-digest-result-form))
     
    104105    (end (string-length (check-string 'message-digest-string str))) )
    105106    (let (
    106       (md (initialize-message-digest mdp)) )
     107      (md (initialized-message-digest mdk)) )
    107108      (check-fixnum-range 'message-digest-string start end)
    108109      (message-digest-update-string md str start end)
    109110      (finalize-message-digest md restyp) ) ) )
    110111
    111 (define (message-digest-blob! mdp blb buf . opts)
     112(define (message-digest-blob! mdk blb buf . opts)
    112113  (let-optionals* opts (
    113114    (start 0)
    114115    (end (blob-size (check-blob 'message-digest-blob! blb))) )
    115116    (let (
    116       (md (initialize-message-digest mdp)) )
     117      (md (initialized-message-digest mdk)) )
    117118      (check-fixnum-range 'message-digest-blob! start end)
    118119      (message-digest-update-blob md blb start end)
    119120      (finalize-message-digest! md buf) ) ) )
    120121
    121 (define (message-digest-string! mdp str buf . opts)
     122(define (message-digest-string! mdk str buf . opts)
    122123  (let-optionals* opts (
    123124    (start 0)
    124125    (end (string-length (check-string 'message-digest-string! str))) )
    125126    (let (
    126       (md (initialize-message-digest mdp)) )
     127      (md (initialized-message-digest mdk)) )
    127128      (check-fixnum-range 'message-digest-string! start end)
    128129      (message-digest-update-string md str start end)
  • release/5/message-digest-utils/trunk/message-digest-item.scm

    r38970 r40448  
    1818  message-digest-port!)
    1919
    20 (import scheme)
    21 (import (chicken base))
    22 (import (chicken type))
    23 (import message-digest-type)
    24 (import message-digest-update-item)
     20(import scheme
     21  (chicken base)
     22  (chicken type)
     23  message-digest-type
     24  message-digest-update-item)
    2525
    2626;;;
     
    3232(define-type pathname string)
    3333
    34 (: message-digest-object (message-digest-primitive * #!rest -> message-digest-result-type))
    35 (: message-digest-file (message-digest-primitive pathname #!rest -> message-digest-result-type))
    36 (: message-digest-port (message-digest-primitive output-port #!rest -> message-digest-result-type))
    37 (: message-digest-object! (message-digest-primitive * message-digest-buffer #!rest -> message-digest-result-type))
    38 (: message-digest-file! (message-digest-primitive pathname message-digest-buffer -> message-digest-result-type))
    39 (: message-digest-port! (message-digest-primitive output-port message-digest-buffer -> message-digest-result-type))
     34(: message-digest-object (message-digest-kind * #!rest -> message-digest-result-type))
     35(: message-digest-file (message-digest-kind pathname #!rest -> message-digest-result-type))
     36(: message-digest-port (message-digest-kind output-port #!rest -> message-digest-result-type))
     37(: message-digest-object! (message-digest-kind * message-digest-buffer #!rest -> message-digest-result-type))
     38(: message-digest-file! (message-digest-kind pathname message-digest-buffer -> message-digest-result-type))
     39(: message-digest-port! (message-digest-kind output-port message-digest-buffer -> message-digest-result-type))
    4040
    4141;; Single Source API
     
    4343;;
    4444
    45 (define (message-digest-object mdp obj . opts)
     45(define (message-digest-object mdk obj . opts)
    4646  (let-optionals* opts (
    4747    (restyp (message-digest-result-form))
    4848    (start 0)
    4949    (end #f) )
    50     (let ((md (initialize-message-digest mdp)))
     50    (let ((md (initialized-message-digest mdk)))
    5151      (message-digest-update-object md obj start end)
    5252      (finalize-message-digest md restyp) ) ) )
    5353
    54 (define (message-digest-file mdp flnm . opts)
     54(define (message-digest-file mdk flnm . opts)
    5555  (let-optionals* opts (
    5656    (restyp (message-digest-result-form)) )
    5757    (let (
    58       (md (initialize-message-digest mdp)) )
     58      (md (initialized-message-digest mdk)) )
    5959      (message-digest-update-file md flnm)
    6060      (finalize-message-digest md restyp) ) ) )
    6161
    62 (define (message-digest-port mdp port . opts)
     62(define (message-digest-port mdk port . opts)
    6363  (let-optionals* opts (
    6464    (restyp (message-digest-result-form)) )
    6565    (let (
    66       (md (initialize-message-digest mdp)) )
     66      (md (initialized-message-digest mdk)) )
    6767      (message-digest-update-port md port)
    6868      (finalize-message-digest md restyp) ) ) )
     
    7070;;
    7171
    72 (define (message-digest-object! mdp obj buf . opts)
     72(define (message-digest-object! mdk obj buf . opts)
    7373  (let-optionals* opts (
    7474    (start 0)
    7575    (end #f) )
    7676    (let (
    77       (md (initialize-message-digest mdp)) )
     77      (md (initialized-message-digest mdk)) )
    7878      (message-digest-update-object md obj start end)
    7979      (finalize-message-digest! md buf) ) ) )
    8080
    81 (define (message-digest-file! mdp flnm buf)
     81(define (message-digest-file! mdk flnm buf)
    8282  (let (
    83     (md (initialize-message-digest mdp)) )
     83    (md (initialized-message-digest mdk)) )
    8484    (message-digest-update-file md flnm)
    8585    (finalize-message-digest! md buf) ) )
    8686
    87 (define (message-digest-port! mdp port buf)
     87(define (message-digest-port! mdk port buf)
    8888  (let (
    89     (md (initialize-message-digest mdp)) )
     89    (md (initialized-message-digest mdk)) )
    9090    (message-digest-update-port md port)
    9191    (finalize-message-digest! md buf) ) )
  • release/5/message-digest-utils/trunk/message-digest-port.scm

    r38970 r40448  
    120120
    121121(define (open-output-digest mdp)
    122   (check-message-digest-primitive 'open-output-digest mdp)
    123122  (let* (
    124123    (md
    125       (initialize-message-digest mdp))
     124      (setup-message-digest (check-message-digest-primitive 'open-output-digest mdp)))
    126125    (writer
    127126      (lambda (obj)
     
    131130          (message-digest-update-blob md obj))))
    132131      ;use default close behavior
    133       (port
    134         (make-output-port writer void)) )
     132    (port
     133      (make-output-port writer void)) )
    135134    (%set-port-data! port md)
    136135    (%port-type-set! port PORT-TAG)
  • release/5/message-digest-utils/trunk/message-digest-srfi-4.scm

    r38970 r40448  
    1616  message-digest-u8vector message-digest-u8vector!)
    1717
    18 (import scheme)
    19 (import (chicken base))
    20 (import (chicken blob))
    21 (import (chicken type))
    22 (import (srfi 4))
    23 (import (only (chicken memory representation) number-of-bytes))
    24 (import (only srfi-4-checks check-u8vector))
    25 (import (only type-errors error-argument-type))
    26 (import message-digest-primitive)
    27 (import message-digest-type)
    28 (import message-digest-support)
    29 (import message-digest-byte-vector)
     18(import scheme
     19  (chicken base)
     20  (chicken blob)
     21  (chicken type)
     22  (srfi 4)
     23  (only (chicken memory representation) number-of-bytes)
     24  (only srfi-4-checks check-u8vector)
     25  (only type-errors error-argument-type)
     26  message-digest-primitive
     27  message-digest-type
     28  message-digest-support
     29  message-digest-byte-vector)
    3030
    3131;; Support
     
    3636
    3737(: get-bytevector-object (symbol * --> blob))
     38
    3839(: message-digest-update-u8vector (message-digest u8vector #!rest -> void))
    39 (: message-digest-u8vector (message-digest-primitive u8vector #!rest -> message-digest-result-type))
    40 (: message-digest-u8vector! (message-digest-primitive u8vector message-digest-buffer #!rest -> message-digest-result-type))
     40
     41(: message-digest-u8vector (message-digest-kind u8vector #!rest -> message-digest-result-type))
     42(: message-digest-u8vector! (message-digest-kind u8vector message-digest-buffer #!rest -> message-digest-result-type))
    4143
    4244;;
     
    4850                ((blob? obj)
    4951                  obj )
    50                 ((packed-vector->blob/shared obj) )
     52                ((packed-vector->blob/shared obj)
     53                  ) ;oh, sneaky
    5154                (else
    5255        (error-argument-type loc obj "string, blob, or SRFI 4 vector" obj) ) ) )
     
    6568;;; Single Source API
    6669
    67 (define (message-digest-u8vector mdp u8vec . opts)
     70(define (message-digest-u8vector mdk u8vec . opts)
    6871  (let-optionals* opts (
    6972    (restyp (message-digest-result-form))
    7073    (start 0)
    7174    (end (u8vector-length u8vec)) )
    72     (let ((md (initialize-message-digest mdp)))
     75    (let ((md (initialized-message-digest mdk)))
    7376      (message-digest-update-u8vector md u8vec start end)
    7477      (finalize-message-digest md restyp) ) ) )
    7578
    76 (define (message-digest-u8vector! mdp u8vec buffer . opts)
     79(define (message-digest-u8vector! mdk u8vec buffer . opts)
    7780  (let-optionals* opts (
    7881    (start 0)
    7982    (end (u8vector-length u8vec)) )
    80     (let ((md (initialize-message-digest mdp)))
     83    (let ((md (initialized-message-digest mdk)))
    8184      (message-digest-update-u8vector md u8vec start end)
    8285      (finalize-message-digest! md buffer) ) ) )
  • release/5/message-digest-utils/trunk/message-digest-type.types.scm

    r39015 r40448  
    33
    44;; Include File
     5
     6(include "message-digest-primitive.types")
    57
    68(define-type srfi4vector
     
    1820
    1921(define-type message-digest (struct message-digest))
     22
     23(define-type message-digest-kind (or message-digest message-digest-primitive))
  • release/5/message-digest-utils/trunk/message-digest-utils.egg

    r40437 r40448  
    33
    44((synopsis "Message Digest Support")
    5  (version "4.2.7")
     5 (version "4.3.0")
    66 (category crypt)
    77 (author "Kon Lovett")
     
    1010  check-errors blob-utils string-utils memory-mapped-files
    1111  message-digest-primitive
    12   message-digest-type)
     12  (message-digest-type "4.3.0"))
    1313 (test-dependencies test)
    1414 (components
  • release/5/message-digest-utils/trunk/message-digest.types.scm

    r38513 r40448  
    55;; Include File
    66
    7 (include "message-digest-primitive.types")
    87(include "message-digest-type.types")
    98
  • release/5/message-digest-utils/trunk/tests/message-digest-utils-test.scm

    r40434 r40448  
    112112  (test-group "string Source"
    113113    (let (
    114       (md (initialize-message-digest mdp)) )
     114      (md (setup-message-digest mdp)) )
    115115      (test-assert (message-digest-update-string md (string #\1 #\2 #\3 #\4 #\5)))
    116116      (test "3132333435" (finalize-message-digest md)) )
     
    119119  (test-group "blob Source"
    120120    (let (
    121       (md (initialize-message-digest mdp)) )
     121      (md (setup-message-digest mdp)) )
    122122      (test-assert (message-digest-update-blob md #${3132333435}))
    123123      (test "3132333435" (finalize-message-digest md)) )
     
    126126  (test-group "u8vector Source"
    127127    (let (
    128       (md (initialize-message-digest mdp)) )
     128      (md (setup-message-digest mdp)) )
    129129      (test-assert (message-digest-update-u8vector md (u8vector 1 2 3 4 5)))
    130130      (test "0102030405" (finalize-message-digest md)) )
     
    133133  (test-group "u8 Source"
    134134    (let (
    135       (md (initialize-message-digest mdp)) )
     135      (md (setup-message-digest mdp)) )
    136136      (test-assert (message-digest-update-u8 md #xA2))
    137137      (test "a200000000" (finalize-message-digest md)) )
     
    140140  (test-group "u16-le Source"
    141141    (let (
    142       (md (initialize-message-digest mdp)) )
     142      (md (setup-message-digest mdp)) )
    143143      (test-assert (message-digest-update-u16-le md #xA2B2))
    144144      (test "b2a2000000" (finalize-message-digest md)) )
     
    147147  (test-group "u32-be Source"
    148148    (let (
    149       (md (initialize-message-digest mdp)) )
     149      (md (setup-message-digest mdp)) )
    150150      (test-assert (message-digest-update-u32-be md 1073741823))
    151151      (test "3fffffff00" (finalize-message-digest md)) )
     
    154154  (test-group "u32-be Source"
    155155    (let (
    156       (md (initialize-message-digest mdp)) )
     156      (md (setup-message-digest mdp)) )
    157157      (test-assert (message-digest-update-u32-be md #xA2B2C2D2))
    158158      (test "a2b2c2d200" (finalize-message-digest md)) )
     
    161161  (test-group "u64-be Source"
    162162    (let (
    163       (md (initialize-message-digest mdp)) )
     163      (md (setup-message-digest mdp)) )
    164164      (test-assert (message-digest-update-u64-be md #xAB54A98CEB1F0AD2))
    165165      (test
     
    170170  (test-group "char-u8 Source"
    171171    (let (
    172       (md (initialize-message-digest mdp)) )
     172      (md (setup-message-digest mdp)) )
    173173      (test-assert (message-digest-update-char-u8 md #\space))
    174174      (test "2000000000" (finalize-message-digest md)) )
     
    177177  (test-group "char-be Source"
    178178    (let (
    179       (md (initialize-message-digest mdp)) )
     179      (md (setup-message-digest mdp)) )
    180180      (test-assert (message-digest-update-char-be md #\u0003BB))
    181181      (test "000003bb00" (finalize-message-digest md)) )
     
    184184  (test-group "char-le Source"
    185185    (let (
    186       (md (initialize-message-digest mdp)) )
     186      (md (setup-message-digest mdp)) )
    187187      (test-assert (message-digest-update-char-le md #\u0003BB))
    188188      (test "bb03000000" (finalize-message-digest md)) )
     
    200200  (test-group "Procedure Source"
    201201    (let (
    202       (md (initialize-message-digest mdp)) )
     202      (md (setup-message-digest mdp)) )
    203203      (test-assert (message-digest-update-procedure md just-once))
    204204      (test simple-res (finalize-message-digest md)) )
     205  )
     206
     207  (test-group "re-use"
     208    (let (
     209      (md (setup-message-digest mdp)) )
     210      (test "3132333435" (message-digest-string md (string #\1 #\2 #\3 #\4 #\5)))
     211      (test "3534333231" (message-digest-string md (string #\5 #\4 #\3 #\2 #\1))) )
    205212  )
    206213)
Note: See TracChangeset for help on using the changeset viewer.