@@ -17,10 +17,13 @@ defmodule Scenic.Cache.Hash do
17
17
end
18
18
19
19
# --------------------------------------------------------
20
+ @ spec valid_hash_types ( ) :: [ :ripemd160 | :sha | :sha224 | :sha256 | :sha384 | :sha512 , ... ]
20
21
def valid_hash_types ( ) , do: @ hash_types
21
22
# --------------------------------------------------------
23
+ @ spec valid_hash_type? ( any ( ) ) :: boolean ( )
22
24
def valid_hash_type? ( hash_type ) , do: Enum . member? ( @ hash_types , hash_type )
23
25
# --------------------------------------------------------
26
+ @ spec valid_hash_type! ( any ( ) ) :: any ( ) | no_return
24
27
def valid_hash_type! ( hash_type ) do
25
28
case Enum . member? ( @ hash_types , hash_type ) do
26
29
true ->
@@ -33,9 +36,10 @@ defmodule Scenic.Cache.Hash do
33
36
end
34
37
35
38
# --------------------------------------------------------
39
+ @ spec binary ( any ( ) , any ( ) ) :: { :error , :invalid_hash_type } | { :ok , binary ( ) }
36
40
def binary ( data , hash_type ) do
37
41
case valid_hash_type? ( hash_type ) do
38
- true -> { :ok , :crypto . hash ( hash_type , data ) |> Base . url_encode64 ( padding: false ) }
42
+ true -> { :ok , hash_type |> :crypto . hash ( data ) |> Base . url_encode64 ( padding: false ) }
39
43
false -> { :error , :invalid_hash_type }
40
44
end
41
45
end
@@ -127,7 +131,7 @@ defmodule Scenic.Cache.Hash do
127
131
end
128
132
end
129
133
130
- # --------------------------------------------------------
134
+ # --------------------------------------------------------
131
135
def verify_file! ( path_data ) , do: path_params ( path_data ) |> do_verify_file! ( )
132
136
133
137
defp do_verify_file! ( { path , hash , hash_type } ) do
@@ -139,7 +143,8 @@ defmodule Scenic.Cache.Hash do
139
143
140
144
# --------------------------------------------------------
141
145
def from_path ( path ) do
142
- String . split ( path , "." )
146
+ path
147
+ |> String . split ( "." )
143
148
|> List . last ( )
144
149
end
145
150
0 commit comments