;;;; message-digest-srfi-4.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 ;;;; Kon Lovett, Aug '17 ;;;; Kon Lovett, Apr '12 ;;;; Kon Lovett, May '10 (message-digest.scm) ;;;; Kon Lovett, Jan '06 (message-digest.scm) ;; Issues ;; ;; - Passes u8vector to update phase as a blob. (module message-digest-srfi-4 (;export message-digest-update-u8vector message-digest-u8vector message-digest-u8vector!) (import scheme (chicken base) (chicken blob) (chicken type) (srfi 4) (only (chicken memory representation) number-of-bytes) (only srfi-4-checks check-u8vector) (only type-errors-basic error-argument-type) message-digest-primitive message-digest-type message-digest-support message-digest-byte-vector) (include-relative "message-digest.types") (: get-bytevector-object (symbol * --> blob)) (: message-digest-update-u8vector (message-digest u8vector #!rest -> void)) (: message-digest-u8vector (message-digest-kind u8vector #!rest -> message-digest-result-type)) (: message-digest-u8vector! (message-digest-kind u8vector message-digest-buffer #!rest -> message-digest-result-type)) ;; (define (get-bytevector-object loc obj) (cond ((string? obj) (string->blob obj) ) ((blob? obj) obj ) ((packed-vector->blob/shared obj) ) ;oh, sneaky (else (error-argument-type loc obj "string, blob, or SRFI 4 vector" obj) ) ) ) ;;; Update API ;; (define (message-digest-update-u8vector md u8vec . opts) (let-optionals* opts ((start 0) (end (u8vector-length u8vec)) ) (message-digest-update-blob md (u8vector->blob/shared (u8vector/slice u8vec start end))) ) ) ;;; Single Source API (define (message-digest-u8vector mdk u8vec . opts) (let-optionals* opts ((restyp (message-digest-result-form)) (start 0) (end (u8vector-length u8vec)) ) (let ((md (initialized-message-digest mdk))) (message-digest-update-u8vector md u8vec start end) (finalize-message-digest md restyp) ) ) ) (define (message-digest-u8vector! mdk u8vec buffer . opts) (let-optionals* opts ((start 0) (end (u8vector-length u8vec)) ) (let ((md (initialized-message-digest mdk))) (message-digest-update-u8vector md u8vec start end) (finalize-message-digest! md buffer) ) ) ) ) ;module message-digest-srfi-4