Skip to content

Commit 9d1d141

Browse files
committed
Support SHA512 hash algorithm (:sha512)
1 parent 3dc4fef commit 9d1d141

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/cavia/core.clj

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
:auth {:access-key-id \"accesskey\", :secret-access-key \"secretkey\"}}
3636
{:id :resource5
3737
:url \"http://example.com/resource5.gz\"
38-
:sha1 \"456789abcdef01234567890abcdef0123456789a\"
38+
:sha512 \"456789abcdef01234567890abcdef0123456789abcdef01234567890abcdef01234567890abcdebcdef01234567890abcdef01234567890abcdebcdef0123456\"
3939
:packed :gzip}]
4040
:download-to \".cavia\"})"
4141
[name profile]
@@ -166,11 +166,12 @@
166166
priority will be used."
167167
{:md5 0
168168
:sha1 1
169-
:sha256 2})
169+
:sha256 2
170+
:sha512 3})
170171

171172
(defn- enabled-hash
172173
[r]
173-
(->> (select-keys r [:md5 :sha1 :sha256])
174+
(->> (select-keys r [:md5 :sha1 :sha256 :sha512])
174175
(sort-by #((first %) hash-algo-order) >)
175176
first))
176177

@@ -181,6 +182,7 @@
181182
:md5 digest/md5
182183
:sha1 digest/sha1
183184
:sha256 digest/sha-256
185+
:sha512 digest/sha-512
184186
(throw (IllegalArgumentException. (str "Invalid hash algorithm: " algo))))
185187
(io/file f))))
186188

test/cavia/core_test.clj

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
{:id :test-resource2
1212
:url "http://localhost:8080/test.png"
1313
:sha1 "unverifiedsha1"}
14-
{:id :test-resource3
14+
{:id :test-resource-md5
1515
:url "http://localhost:8080/test.png"
1616
:md5 "0656b409231ee9bd8c5c9272647c69a1"}
17-
{:id :test-resource4
17+
{:id :test-resource-sha256
1818
:url "http://localhost:8080/test.png"
1919
:sha256 "55902cd4056e2bd57ced9296c826e4df42f07457c96ce72afe8652d0d6dd89b3"}
20+
{:id :test-resource-sha512
21+
:url "http://localhost:8080/test.png"
22+
:sha512 "71122b126cf93561275d711d543bd09db82f68637a603fec49e5e0a1312a1e3749580650d8adbd8989affe036a052019d7602c53f2456f117c1960c35b091ccb"}
2023
{:id :test-resource-gzip
2124
:url "http://localhost:8080/test.png.gz"
2225
:sha1 "07dba3bd9f227f58134d339b1609e0a913abe0de"
@@ -75,8 +78,9 @@
7578
(testing "returns true if the file's hash is valid"
7679
(are [k] (true? (cavia/valid? k))
7780
:test-resource
78-
:test-resource3
79-
:test-resource4
81+
:test-resource-md5
82+
:test-resource-sha256
83+
:test-resource-sha512
8084
:test-resource-ftp
8185
:test-resource-s3))
8286
(testing "returns false if the file's hash is invalid"

0 commit comments

Comments
 (0)