File tree Expand file tree Collapse file tree 2 files changed +39
-10
lines changed
Expand file tree Collapse file tree 2 files changed +39
-10
lines changed Original file line number Diff line number Diff line change 2929 end
3030end
3131local hmac_sha256
32- hmac_sha256 = function (key , str )
33- local openssl_hmac = require (" openssl.hmac" )
34- local hmac = assert (openssl_hmac .new (key , " sha256" ))
35- hmac :update (str )
36- return assert (hmac :final ())
32+ if pcall (function ()
33+ return require (" openssl.hmac" )
34+ end ) then
35+ hmac_sha256 = function (key , str )
36+ local openssl_hmac = require (" openssl.hmac" )
37+ local hmac = assert (openssl_hmac .new (key , " sha256" ))
38+ hmac :update (str )
39+ return assert (hmac :final ())
40+ end
41+ elseif pcall (function ()
42+ return require (" resty.openssl.hmac" )
43+ end ) then
44+ hmac_sha256 = function (key , str )
45+ local openssl_hmac = require (" resty.openssl.hmac" )
46+ local hmac = assert (openssl_hmac .new (key , " sha256" ))
47+ hmac :update (str )
48+ return assert (hmac :final ())
49+ end
50+ else
51+ hmac_sha256 = function ()
52+ return error (" Either luaossl or resty.openssl is required to calculate hmac sha256 digest" )
53+ end
3754end
3855local digest_sha256
3956digest_sha256 = function (str )
Original file line number Diff line number Diff line change @@ -13,12 +13,24 @@ elseif pcall -> require "crypto"
1313else
1414 -> error " Either luaossl (recommended) or LuaCrypto is required to calculate md5"
1515
16- hmac_sha256 = ( key, str) ->
17- openssl_hmac = require ( " openssl.hmac" )
18- hmac = assert openssl_hmac. new( key, " sha256" )
1916
20- hmac\ update str
21- assert hmac\ final!
17+ hmac_sha256 = if pcall -> require " openssl.hmac"
18+ ( key, str) ->
19+ openssl_hmac = require ( " openssl.hmac" )
20+ hmac = assert openssl_hmac. new( key, " sha256" )
21+
22+ hmac\ update str
23+ assert hmac\ final!
24+ elseif pcall -> require " resty.openssl.hmac"
25+ ( key, str) ->
26+ openssl_hmac = require ( " resty.openssl.hmac" )
27+ hmac = assert openssl_hmac. new( key, " sha256" )
28+
29+ hmac\ update str
30+ assert hmac\ final!
31+ else
32+ -> error " Either luaossl or resty.openssl is required to calculate hmac sha256 digest"
33+
2234
2335digest_sha256 = ( str) ->
2436 digest = assert require ( " openssl.digest" ) . new( " sha256" )
You can’t perform that action at this time.
0 commit comments