Initial import
This commit is contained in:
@@ -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))
|
||||
Reference in New Issue
Block a user