Ignore:
Timestamp:
03/25/18 19:50:42 (2 years ago)
Author:
Kon Lovett
Message:

add types, message-digest-result-form -> -type, -form is symbol, -byte-order is symbol, do not type check-/error- (no no no no no)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/message-digest/trunk/message-digest-type.scm

    r35339 r35341  
    6060;assumes blob 'res' may not be of result size
    6161
    62 (define: (get-result-form (loc symbol) (res blob) (rt symbol)) -> message-digest-result-form
    63   (case (canonical-result-name rt)
     62(define: (get-result-form (loc symbol) (res blob) (restyp message-digest-result-form)) -> message-digest-result-type
     63  (case (canonical-result-name restyp)
    6464    ((blob)           res )
    6565    ((byte-string)    (blob->string res) )
     
    6767    ((u8vector)       (blob->u8vector/shared res) )
    6868    (else
    69       (error-result-form loc rt) ) ) )
     69      (error-result-form loc restyp) ) ) )
    7070
    7171#;
    72 (define: (get-result-form (loc symbol) (res blob) (rt symbol)) -> message-digest-result-form
    73   (case rt
     72(define: (get-result-form (loc symbol) (res blob) (restyp message-digest-result-form)) -> message-digest-result-type
     73  (case restyp
    7474    ((blob)
    7575      (if (fx= len (blob-size res)) res
     
    8686          (subu8vector vec 0 len) ) ) )
    8787    (else
    88       (error-result-form loc rt) ) ) )
    89 
    90 (define: (canonical-result-name (x symbol)) -> (or boolean symbol)
     88      (error-result-form loc restyp) ) ) )
     89
     90(define: (canonical-result-name (x message-digest-result-form)) -> (or boolean message-digest-result-form)
    9191  (case x
    9292    ((blob)                       'blob )
     
    9797      #f ) ) )
    9898
    99 (define: (check-result-type (loc symbol) (mdp message-digest-primitive) (obj message-digest-result-form)) -> message-digest-result-form
     99(define: (check-result-type (loc symbol) (mdp message-digest-primitive) (obj message-digest-result-type)) -> message-digest-result-type
    100100  (let (
    101101    (siz
     
    119119;;
    120120
    121 (: message-digest-result-form (#!optional symbol -> symbol))
     121(: message-digest-result-form (#!optional message-digest-result-form -> message-digest-result-form))
    122122;
    123123(define-parameter message-digest-result-form #;DEFAULT-RESULT-TYPE 'hex-string
     
    162162;;
    163163
    164 (define: (finalize-message-digest (md message-digest) . (opts (list-of message-digest-result-form))) -> message-digest-result-form
     164(define: (finalize-message-digest (md message-digest) . (opts (list message-digest-result-type))) -> message-digest-result-type
    165165  (let* (
    166     (result-type
    167       (optional opts (message-digest-result-form)))
    168     (mdp
    169       (message-digest-algorithm (check-message-digest 'finalize-message-digest md)))
    170     (res
    171       (make-blob (message-digest-primitive-digest-length mdp))) )
     166    (restyp (optional opts (message-digest-result-form)))
     167    (mdp (message-digest-algorithm (check-message-digest 'finalize-message-digest md)))
     168    (res (make-blob (message-digest-primitive-digest-length mdp))) )
    172169    ;side-effects res
    173170    ((message-digest-primitive-final mdp) (message-digest-context md) res)
    174     (get-result-form 'finalize-message-digest res result-type) ) )
    175 
    176 (define: (finalize-message-digest! (md message-digest) (result-buffer message-digest-buffer)) -> message-digest-result-form
     171    (get-result-form 'finalize-message-digest res restyp) ) )
     172
     173(define: (finalize-message-digest! (md message-digest) (result-buffer message-digest-buffer)) -> message-digest-result-type
    177174  (let* (
    178175    (mdp
     
    192189    (sz (fxmax sz MINIMUM-BUFFER-SIZE)) )
    193190    ;enough space? then reuse, otherwise new buffer
    194     (if buf (print "buf " buf))
    195191    (if (and buf (fx<= sz (number-of-bytes buf)))
    196192      buf
Note: See TracChangeset for help on using the changeset viewer.