AtlatestRepositorysigil-quic
sigil-quic / tree / scriptsfactory-spy.sgl
1
;;; Test-only actual returned-buffer references; faults occur before allocation.2
(define-library (sigil quic tests factory spy)3
(import (sigil crypto)4
(sigil quic tls schedule))5
(export factory-spy-reset! factory-spy-fail! factory-spy-records6
factory-spy-extract factory-spy-expand factory-spy-copy)7
(begin8
(define captured '())9
(define failure #f)11
(define (factory-spy-reset!)12
(set! captured '())13
(set! failure #f))15
(define (factory-spy-fail! stage)16
(set! failure stage))18
(define (factory-spy-records)19
captured)21
(define (checkpoint! stage)22
(when (and failure (string=? failure stage))23
(error "QL7 injected factory failure" stage)))25
(define (observe! kind bytes)26
(let ((nonzero?27
(let loop ((i 0))28
(and (< i (bytevector-length bytes))29
(or (not (= (bytevector-u8-ref bytes i) 0))30
(loop (+ i 1)))))))31
(set! captured (cons (vector kind bytes nonzero?) captured)))32
bytes)34
(define (factory-spy-extract salt input)35
(observe! "initial root" (hkdf-sha256-extract salt input)))37
(define (factory-spy-expand secret label context size)38
(checkpoint! label)39
(observe! label (hkdf-expand-label secret label context size)))41
(define (factory-spy-copy bytes)42
(let ((kind (if (= (bytevector-length bytes) 32) "copy secret" "copy hp")))43
(checkpoint! kind)44
(observe! kind (bytevector-copy bytes))))))