file/sha1: fix problem with leading zeros

Closes PR 13212
This commit is contained in:
Danny Yoo 2012-11-06 14:28:18 -07:00 committed by Matthew Flatt
parent 054a52f547
commit 1b4ebef117
2 changed files with 10 additions and 1 deletions

View File

@ -290,7 +290,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(sha1-hash-bytes (get-output-bytes p))))
(define (sha1 in)
(format "~x" (sha1-input in)))
(bytes->hex-string (hash-value->bytes (sha1-input in))))
(define (sha1-bytes in)
(hash-value->bytes (sha1-input in)))

View File

@ -0,0 +1,9 @@
#lang racket/base
(require file/sha1 rackunit)
;; The docs say that sha1 must return a 40-character string,
;; and should include leading zeros.
(check-equal? (string-length (sha1 (open-input-string " r a c k et")))
40)