Changeset 40447 in project


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

deprecate initialize-*, add setup- to initialize from a primitive, add reset- to re-initialize a digest, initialized- to auto-select

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

Legend:

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

    r40440 r40447  
    44
    55((synopsis "Message Digest Type")
    6  (version "4.2.5")
     6 (version "4.3.0")
    77 (category crypt)
    88 (author "Kon Lovett")
  • release/5/message-digest-type/trunk/message-digest-type.scm

    r38984 r40447  
    2424  message-digest? check-message-digest error-message-digest
    2525  message-digest-algorithm message-digest-context
    26   initialize-message-digest initialize-message-digest!
     26  ;
    2727  ensure-message-digest-buffer!
    28   finalize-message-digest finalize-message-digest!)
    29 
    30 (import scheme)
    31 (import (chicken base))
    32 (import (chicken type))
    33 (import (chicken blob))
    34 (import (only (chicken memory representation) number-of-bytes))
    35 (import (only (srfi 4) blob->u8vector/shared u8vector-length u8vector?))
    36 (import (only blob-hexadecimal blob->hex))
    37 (import (only string-hexadecimal string->hex))
    38 (import (only type-checks define-check+error-type check-positive-fixnum))
    39 (import (only type-errors error-argument-type))
    40 (import message-digest-primitive)
     28  ;
     29  setup-message-digest
     30  reset-message-digest!
     31  initialized-message-digest
     32  finalize-message-digest finalize-message-digest!
     33  ;
     34  initialize-message-digest initialize-message-digest!)
     35
     36(import scheme
     37  (chicken base)
     38  (chicken type)
     39  (chicken blob)
     40  (only (chicken memory representation) number-of-bytes)
     41  (only (srfi 4) blob->u8vector/shared u8vector-length u8vector?)
     42  (only blob-hexadecimal blob->hex)
     43  (only string-hexadecimal string->hex)
     44  (only type-checks define-check+error-type check-positive-fixnum)
     45  (only type-errors error-argument-type)
     46  message-digest-primitive)
    4147
    4248;;; Support
     
    4450;;
    4551
    46 (include "message-digest-primitive.types")
    4752(include "message-digest-type.types")
    4853
     
    5156(: check-result-type (symbol message-digest-primitive message-digest-result-type -> message-digest-result-type))
    5257(: message-digest-result-form (#!optional message-digest-result-form -> message-digest-result-form))
     58
    5359(: *make-message-digest (message-digest-primitive message-digest-primitive-context (or boolean message-digest-buffer) -> message-digest))
    5460(: message-digest? (* -> boolean : message-digest))
     
    5763(: message-digest-buffer (message-digest -> (or boolean message-digest-buffer)))
    5864(: message-digest-buffer-set! (message-digest (or boolean message-digest-buffer) -> void))
    59 (: new-message-digest-buffer (message-digest fixnum -> message-digest-buffer))
    60 (: new-message-digest (message-digest-primitive message-digest-primitive-context -> message-digest))
    61 (: *finalize-message-digest (message-digest-buffer message-digest message-digest-primitive -> message-digest-buffer))
    62 (: initialize-message-digest (message-digest-primitive -> message-digest))
     65
     66(: *new-message-digest-buffer! (message-digest fixnum -> message-digest-buffer))
     67(: *reset-message-digest! (message-digest -> message-digest))
     68(: *finalize-message-digest! (message-digest-buffer message-digest message-digest-primitive -> message-digest-buffer))
     69
     70(: setup-message-digest (message-digest-primitive #!optional message-digest-primitive-context -> message-digest))
     71(: reset-message-digest! (message-digest -> message-digest))
     72(: initialized-message-digest (message-digest-kind -> message-digest))
     73
    6374(: ensure-message-digest-buffer! (message-digest fixnum -> message-digest-buffer))
     75
    6476(: finalize-message-digest (message-digest #!optional message-digest-result-form -> message-digest-result-type))
    6577(: finalize-message-digest! (message-digest message-digest-buffer -> message-digest-result-type))
     
    169181
    170182;
    171 (define-inline (new-message-digest-buffer md siz)
     183(define-inline (*new-message-digest-buffer! md siz)
     184  ;side-effects md
    172185  (let ((buf (make-blob siz)))
    173186    (message-digest-buffer-set! md buf)
     
    175188
    176189;
    177 (define-inline (new-message-digest mdp ctx)
    178   ((message-digest-primitive-init mdp) ctx)
    179   (*make-message-digest mdp ctx #f) )
    180 
    181 ;
    182 (define-inline (*finalize-message-digest res md mdp)
     190(define-inline (*reset-message-digest! md)
     191  ;side-effects ctx
     192  ((message-digest-primitive-init (message-digest-algorithm md)) (message-digest-context md))
     193  md )
     194
     195;
     196(define-inline (*finalize-message-digest! res md mdp)
    183197  ;side-effects res
    184198  (let ((buf (if (u8vector? res) (%u8vector-blob res) res)))
     
    189203
    190204;
    191 (define (initialize-message-digest mdp)
    192   ;(check-message-digest-primitive 'initialize-message-digest mdp)
    193   (new-message-digest mdp (make-message-digest-primitive-context mdp)) )
    194 
    195 (: initialize-message-digest! (message-digest-primitive message-digest-primitive-context -> message-digest))
    196 ;
    197 (define (initialize-message-digest! mdp ctx)
    198   (new-message-digest (check-message-digest-primitive 'initialize-message-digest! mdp) ctx) )
     205(define (reset-message-digest! md)
     206  (*reset-message-digest! (check-message-digest 'reset-message-digest! md)) )
     207
     208;
     209(define (setup-message-digest mdp #!optional ctx)
     210  (check-message-digest-primitive 'setup-message-digest mdp)
     211  (let ((ctx (or ctx (make-message-digest-primitive-context mdp))))
     212    (*reset-message-digest! (*make-message-digest mdp ctx #f)) ) )
     213
     214;
     215(define (initialized-message-digest mdp-or-md)
     216  (if (message-digest? mdp-or-md)
     217    (*reset-message-digest! mdp-or-md)
     218    (setup-message-digest mdp-or-md) ) )
     219
     220;;
     221
     222(define initialize-message-digest setup-message-digest)
     223(define initialize-message-digest! setup-message-digest)
     224
     225(: initialize-message-digest (deprecated setup-message-digest))
     226(: initialize-message-digest! (deprecated setup-message-digest))
    199227
    200228;;
     
    210238    (if (and buf (<= siz (number-of-bytes buf)))
    211239      buf
    212       (new-message-digest-buffer md siz) ) ) )
    213 
    214 ;;
     240      (*new-message-digest-buffer! md siz) ) ) )
     241
     242;;
     243
     244(define (make-result-buffer mdp)
     245  (make-blob (message-digest-primitive-digest-length mdp)) )
    215246
    216247;
     
    218249  (let* (
    219250    (mdp (message-digest-algorithm (check-message-digest 'finalize-message-digest md)))
    220     (res (make-blob (message-digest-primitive-digest-length mdp))) )
    221     (*finalize-message-digest res md mdp)
     251    (res (make-result-buffer mdp)) )
     252    (*finalize-message-digest! res md mdp)
    222253    (get-result-form 'finalize-message-digest res restyp) ) )
    223254
     
    227258    (mdp (message-digest-algorithm (check-message-digest 'finalize-message-digest! md)))
    228259    (res (check-result-type 'finalize-message-digest mdp resbuf)) )
    229     (*finalize-message-digest res md mdp) ) )
     260    (*finalize-message-digest! res md mdp) ) )
    230261
    231262) ;module message-digest-type
  • release/5/message-digest-type/trunk/message-digest-type.types.scm

    r38512 r40447  
    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-type/trunk/tests/message-digest-type-test.scm

    r38494 r40447  
    5151  (define mdp (make-message-digest-primitive make-context DIGEST-LENGTH init update final))
    5252
     53  ;FIXME poor test
    5354  (test-group "init & final"
    5455    (let (
    55       (md (initialize-message-digest mdp)) )
     56      (md (initialized-message-digest mdp)) )
    5657      (test-assert (message-digest? md))
    57       (test "0000000000" (finalize-message-digest md)) )
     58      (test "0000000000" (finalize-message-digest md))
     59      (test-assert "re-init" (eq? md (initialized-message-digest md)))
     60      (test "re-done" "0000000000" (finalize-message-digest md)) )
    5861  )
    5962)
Note: See TracChangeset for help on using the changeset viewer.