@@ -16,7 +16,7 @@ local cipher_ctx_ptr_ct = ffi.typeof('EVP_CIPHER_CTX*')
16
16
17
17
function _M .new (typ )
18
18
if not typ then
19
- return nil , " expect type to be defined"
19
+ return nil , " cipher.new: expect type to be defined"
20
20
end
21
21
22
22
local ctx
@@ -29,12 +29,12 @@ function _M.new(typ)
29
29
ffi_gc (ctx , C .EVP_CIPHER_CTX_cleanup )
30
30
end
31
31
if ctx == nil then
32
- return nil , " failed to create EVP_CIPHER_CTX"
32
+ return nil , " cipher.new: failed to create EVP_CIPHER_CTX"
33
33
end
34
34
35
35
local dtyp = C .EVP_get_cipherbyname (typ )
36
36
if dtyp == nil then
37
- return nil , string.format (" invalid cipher type \" %s\" " , typ )
37
+ return nil , string.format (" cipher.new: invalid cipher type \" %s\" " , typ )
38
38
end
39
39
40
40
local code = C .EVP_CipherInit_ex (ctx , dtyp , nil , " " , nil , - 1 )
58
58
function _M :init (key , iv , opts )
59
59
opts = opts or {}
60
60
if not key or # key ~= self .key_size then
61
- return false , string.format (" incorrect key size, expect %d" , self .key_size )
61
+ return false , string.format (" cipher:init: incorrect key size, expect %d" , self .key_size )
62
62
end
63
63
if not iv or # iv ~= self .iv_size then
64
- return false , string.format (" incorrect iv size, expect %d" , self .iv_size )
64
+ return false , string.format (" cipher:init: incorrect iv size, expect %d" , self .iv_size )
65
65
end
66
66
67
67
if C .EVP_CipherInit_ex (self .ctx , nil , nil , key , iv , opts .is_encrypt and 1 or 0 ) == 0 then
103
103
local int_ptr = ffi .typeof (" int[1]" )
104
104
function _M :update (...)
105
105
if not self .initialized then
106
- return nil , " cipher not initalized, call cipher:init first"
106
+ return nil , " cipher:update: cipher not initalized, call cipher:init first"
107
107
end
108
108
109
109
local ret = {}
@@ -146,31 +146,31 @@ end
146
146
147
147
function _M :derive (key , salt , count , md )
148
148
if type (key ) ~= " string" then
149
- return nil , nil , " expect a string at #1"
149
+ return nil , nil , " cipher:derive: expect a string at #1"
150
150
elseif salt and type (salt ) ~= " string" then
151
- return nil , nil , " expect a string at #2"
151
+ return nil , nil , " cipher:derive: expect a string at #2"
152
152
elseif count then
153
153
count = tonumber (count )
154
154
if not count then
155
- return nil , nil , " expect a number at #3"
155
+ return nil , nil , " cipher:derive: expect a number at #3"
156
156
end
157
157
elseif md and type (md ) ~= " string" then
158
- return nil , nil , " expect a string or nil at #4"
158
+ return nil , nil , " cipher:derive: expect a string or nil at #4"
159
159
end
160
160
161
161
if salt then
162
162
if # salt > 8 then
163
- ngx .log (ngx .WARN , " salt is too long, truncate salt to 8 bytes" )
163
+ ngx .log (ngx .WARN , " cipher:derive: salt is too long, truncate salt to 8 bytes" )
164
164
salt = salt :sub (0 , 8 )
165
165
elseif # salt < 8 then
166
- ngx .log (ngx .WARN , " salt is too short, padding with zero bytes to length" )
166
+ ngx .log (ngx .WARN , " cipher:derive: salt is too short, padding with zero bytes to length" )
167
167
salt = salt .. string.rep (' \000 ' , 8 - # salt )
168
168
end
169
169
end
170
170
171
171
local mdt = C .EVP_get_digestbyname (md or ' sha1' )
172
172
if mdt == nil then
173
- return nil , nil , string.format (" invalid digest type \" %s\" " , md )
173
+ return nil , nil , string.format (" cipher:derive: invalid digest type \" %s\" " , md )
174
174
end
175
175
local cipt = C .EVP_CIPHER_CTX_cipher (self .ctx )
176
176
local keyb = ffi_new (' unsigned char[?]' , self .key_size )
0 commit comments