@@ -28,8 +28,8 @@ defmodule Scenic.Cache.Hash do
28
28
| :sha512
29
29
| :ripemd160
30
30
31
- @ type type_error :: { :error , :invalid_hash_type }
32
- @ type hash_error :: { :error , :hash_failure }
31
+ # @type type_error :: {:error, :invalid_hash_type}
32
+ # @type hash_error :: {:error, :hash_failure}
33
33
34
34
# ===========================================================================
35
35
defmodule Error do
@@ -67,7 +67,8 @@ defmodule Scenic.Cache.Hash do
67
67
68
68
Returns the hash wrapped in a `{:ok, hash}` tuple.
69
69
"""
70
- @ spec binary ( data :: binary , type :: hash_type ) :: { :ok , bitstring ( ) } | type_error
70
+ @ spec binary ( data :: binary , type :: hash_type ) ::
71
+ { :ok , bitstring ( ) } | { :error , :invalid_hash_type }
71
72
def binary ( data , type ) do
72
73
case valid_hash_type? ( type ) do
73
74
true -> { :ok , type |> :crypto . hash ( data ) |> Base . url_encode64 ( padding: false ) }
@@ -88,7 +89,8 @@ defmodule Scenic.Cache.Hash do
88
89
end
89
90
90
91
# --------------------------------------------------------
91
- @ spec file ( path :: bitstring , type :: hash_type ) :: { :ok , bitstring ( ) } | type_error
92
+ @ spec file ( path :: bitstring , type :: hash_type ) ::
93
+ { :ok , bitstring ( ) } | { :error , :invalid_hash_type }
92
94
def file ( path , hash_type ) do
93
95
do_compute_file (
94
96
path ,
@@ -145,7 +147,8 @@ defmodule Scenic.Cache.Hash do
145
147
If the verification passes, returns `{:ok, data}`
146
148
If it fails, returns `{:error, :hash_failure}`
147
149
"""
148
- @ spec verify ( data :: binary , hash :: bitstring , type :: hash_type ) :: { :ok , binary } | hash_error
150
+ @ spec verify ( data :: binary , hash :: bitstring , type :: hash_type ) ::
151
+ { :ok , binary } | { :error , :hash_failure }
149
152
def verify ( data , hash , hash_type ) do
150
153
case binary ( data , hash_type ) do
151
154
{ :ok , ^ hash } -> { :ok , data }
@@ -176,7 +179,7 @@ defmodule Scenic.Cache.Hash do
176
179
If it fails, returns `{:error, :hash_failure}`
177
180
"""
178
181
@ spec verify_file ( path :: bitstring , hash :: bitstring , type :: hash_type ) ::
179
- binary | hash_error
182
+ { :ok , binary } | { :error , :hash_failure }
180
183
def verify_file ( path , hash , hash_type ) do
181
184
case file ( path , hash_type ) do
182
185
{ :ok , computed_hash } ->
0 commit comments