Coverage report: /home/ellis/comp/core/lib/cry/b3.lisp

KindCoveredAll%
expression3253 60.4
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; b3.lisp --- BLAKE3 Hasher
2
 
3
 ;; 
4
 
5
 ;;; Code:
6
 (in-package :cry/b3)
7
 
8
 (defun b3hash (in &optional (len +blake3-out-len+))
9
   "Hash the sequence IN using blake3 returning an OCTET-VECTOR of length LEN."
10
     (let ((out (make-octets len)))
11
       (with-blake3-hasher h
12
         (with-alien ((input (* unsigned-char) (octets-to-alien in))
13
                      (output (* unsigned-char) (make-alien unsigned-char len)))
14
           (blake3-hasher-update (addr h) input (length in))
15
           (blake3-hasher-finalize (addr h) output len)
16
           (clone-octets-from-alien output out len)
17
           out))))
18
 
19
 (defun b3hash-string (in &key (length +blake3-out-len+) (hex t))
20
   "Hash a string using BLAKE3. When HEX is T (the default) return a hex-encoded
21
 string instead of octets."
22
   (let ((hash (b3hash (sb-ext:string-to-octets in) length)))
23
     (if hex
24
         (octet-vector-to-hex-string hash)
25
         hash)))
26
   
27
 (defun b3sum (path &key (hex t))
28
   (with-open-file (f path :element-type 'octet)
29
     (let ((out (make-octets (file-length f))))
30
       (read-sequence out f)
31
       (let ((hash (b3hash out)))
32
         (if hex
33
             (octet-vector-to-hex-string hash)
34
             hash)))))