@@ -86,14 +86,15 @@ int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md, const unsigned char
8686local ctx_ptr_type = ffi .typeof (" EVP_CIPHER_CTX[1]" )
8787
8888hash = {
89- md5 = C .EVP_md5 (),
90- sha1 = C .EVP_sha1 (),
91- sha224 = C .EVP_sha224 (),
92- sha256 = C .EVP_sha256 (),
93- sha384 = C .EVP_sha384 (),
94- sha512 = C .EVP_sha512 ()
89+ md5 = C .EVP_md5 (),
90+ sha1 = C .EVP_sha1 (),
91+ sha224 = C .EVP_sha224 (),
92+ sha256 = C .EVP_sha256 (),
93+ sha384 = C .EVP_sha384 (),
94+ sha512 = C .EVP_sha512 ()
9595}
9696
97+
9798function cipher (size , _cipher )
9899 local _size = size or 128
99100 local _cipher = _cipher or " cbc"
@@ -105,6 +106,7 @@ function cipher(size, _cipher)
105106 end
106107end
107108
109+
108110function new (self , key , salt , _cipher , _hash , hash_rounds )
109111 local encrypt_ctx = ffi_new (ctx_ptr_type )
110112 local decrypt_ctx = ffi_new (ctx_ptr_type )
@@ -162,6 +164,7 @@ function new(self, key, salt, _cipher, _hash, hash_rounds)
162164 }, mt )
163165end
164166
167+
165168function encrypt (self , s )
166169 local s_len = # s
167170 local max_len = s_len + 16
@@ -185,6 +188,7 @@ function encrypt(self, s)
185188 return ffi_str (buf , out_len [0 ] + tmp_len [0 ])
186189end
187190
191+
188192function decrypt (self , s )
189193 local s_len = # s
190194 local buf = ffi_new (" unsigned char[?]" , s_len )
@@ -207,8 +211,10 @@ function decrypt(self, s)
207211 return ffi_str (buf , out_len [0 ] + tmp_len [0 ])
208212end
209213
214+
210215-- to prevent use of casual module global variables
211216getmetatable (resty .aes ).__newindex = function (table , key , val )
212217 error (' attempt to write to undeclared variable "' .. key .. ' ": '
213218 .. debug.traceback ())
214219end
220+
0 commit comments