Initial import

This commit is contained in:
2026-06-08 17:20:12 +02:00
parent a3c561d2f2
commit 5e860a3d8b
16 changed files with 702 additions and 1 deletions
+20
View File
@@ -0,0 +1,20 @@
#lang racket/base
(require openssl/sha1
openssl/md5)
(provide file-digest)
(define (digest->string v)
(cond [(bytes? v) (bytes->hex-string v)]
[(string? v) v]
[else (format "~a" v)]))
(define (file-digest path [algorithm "sha256"])
(define alg (string-downcase (format "~a" algorithm)))
(call-with-input-file path
(lambda (in)
(cond [(member alg '("sha256" "sha-256" "sha2")) (digest->string (sha256-bytes in))]
[(member alg '("md5")) (digest->string (md5 in))]
[else (error 'file-digest "unsupported digest algorithm: ~a" algorithm)]))
#:mode 'binary))