Skip to content

Commit 764074d

Browse files
committed
chore: update/cleanup resty.string annotations
1 parent 19591ff commit 764074d

File tree

10 files changed

+219
-67
lines changed

10 files changed

+219
-67
lines changed
Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,75 @@
11
---@meta
2-
resty_aes={}
3-
function resty_aes.cipher() end
4-
resty_aes.hash={}
5-
resty_aes.hash.sha1={}
6-
resty_aes.hash.md5={}
7-
resty_aes.hash.sha224={}
8-
resty_aes.hash.sha512={}
9-
resty_aes.hash.sha256={}
10-
resty_aes.hash.sha384={}
11-
function resty_aes.new(self, key, salt, _cipher, _hash, hash_rounds) end
12-
function resty_aes.decrypt(self, s) end
13-
resty_aes._VERSION="0.11"
14-
function resty_aes.encrypt(self, s) end
15-
return resty_aes
2+
3+
local aes={}
4+
5+
---@alias resty.aes.cipher.name
6+
---| '"ecb"'
7+
---| '"cbc"'
8+
---| '"cfb1"'
9+
---| '"cfb128"'
10+
---| '"cfb8"'
11+
---| '"ctr"
12+
---| '"gcm"'
13+
---| '"ofb"'
14+
15+
---@alias resty.aes.cipher.size '128'|'192'|'256'
16+
17+
---@class resty.aes.cipher : table
18+
---@field size resty.aes.cipher.size
19+
---@field cipher resty.aes.cipher.name
20+
---@field method userdata
21+
22+
---@param size resty.aes.cipher.size # cipher size (default `128`)
23+
---@param cipher? resty.aes.cipher.name # cipher name (default `"cbc"`)
24+
---@return resty.aes.cipher?
25+
function aes.cipher(size, cipher) end
26+
27+
---@class resty.aes.hash_table : table
28+
---@field iv string
29+
---@field method? fun(key:string):string
30+
31+
---@class resty.aes.hash_cdata : userdata
32+
33+
---@type table<string, resty.aes.hash_cdata>
34+
aes.hash = {}
35+
aes.hash.sha1={}
36+
aes.hash.md5={}
37+
aes.hash.sha224={}
38+
aes.hash.sha512={}
39+
aes.hash.sha256={}
40+
aes.hash.sha384={}
41+
42+
---@alias resty.aes.hash resty.aes.hash_cdata|resty.aes.hash_table
43+
44+
---@param key string encryption key
45+
---@param salt? string if provided, must be exactly 8 characters in length
46+
---@param cipher? resty.aes.cipher (default is 128 CBC)
47+
---@param hash? resty.aes.hash (default is md5)
48+
---@param hash_rounds? number (default: `1`)
49+
---@param iv_len? number
50+
---@param enable_padding? boolean (default: `true`)
51+
---
52+
---@return resty.aes?
53+
---@return string? error
54+
function aes:new(key, salt, cipher, hash, hash_rounds, iv_len, enable_padding) end
55+
56+
---@class resty.aes : table
57+
local aes_ctx = {}
58+
59+
--- Decrypt a string
60+
---
61+
---@param s string
62+
---@param tag? string
63+
---@return string? decrypted
64+
---@return string? error
65+
function aes_ctx:decrypt(s, tag) end
66+
67+
68+
--- Encrypt a string.
69+
---
70+
---@param s string
71+
---@return string? encrypted
72+
---@return string? error
73+
function aes_ctx:encrypt(s) end
74+
75+
return aes
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
---@meta
2-
resty_md5={}
3-
function resty_md5.final(self) end
4-
function resty_md5.new(self) end
5-
function resty_md5.reset(self) end
6-
resty_md5._VERSION="0.11"
7-
function resty_md5.update(self, s) end
8-
return resty_md5
2+
3+
---@class resty.md5 : resty.string.checksum
4+
local md5={}
5+
6+
--- Create a new md5 checksum object.
7+
---@return resty.md5
8+
function md5:new() end
9+
10+
--- Add a string to the md5 checksum data
11+
---@param s string
12+
---@param len? number Optional length (defaults to the length of `s`)
13+
---@return boolean ok
14+
function md5:update(s, len) end
15+
16+
return md5
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---@meta
2-
resty_random={}
3-
resty_random._VERSION="0.11"
4-
function resty_random.bytes(len, strong) end
5-
return resty_random
2+
local random={}
3+
4+
--- Generate random bytes.
5+
---@param len integer
6+
---@param strong boolean
7+
---@return string
8+
function random.bytes(len, strong) end
9+
10+
return random
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---@meta
2-
resty_sha={}
3-
resty_sha._VERSION="0.11"
2+
local resty_sha={}
3+
resty_sha._VERSION = require("resty.string")._VERSION
44
return resty_sha
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---@meta
2-
resty_sha1={}
3-
function resty_sha1.final(self) end
4-
function resty_sha1.new(self) end
5-
function resty_sha1.reset(self) end
6-
resty_sha1._VERSION="0.11"
7-
function resty_sha1.update(self, s) end
8-
return resty_sha1
2+
3+
---@class resty.sha1 : resty.string.checksum
4+
local sha1={}
5+
6+
--- Create a new sha1 checksum object.
7+
---@return resty.sha1
8+
function sha1:new() end
9+
10+
return sha1
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---@meta
2-
resty_sha224={}
3-
function resty_sha224.final(self) end
4-
function resty_sha224.new(self) end
5-
function resty_sha224.reset(self) end
6-
resty_sha224._VERSION="0.11"
7-
function resty_sha224.update(self, s) end
8-
return resty_sha224
2+
3+
---@class resty.sha244 : resty.string.checksum
4+
local sha224={}
5+
6+
--- Create a new sha244 checksum object.
7+
---@return resty.sha244
8+
function sha224:new() end
9+
10+
return sha224
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---@meta
2-
resty_sha256={}
3-
function resty_sha256.final(self) end
4-
function resty_sha256.new(self) end
5-
function resty_sha256.reset(self) end
6-
resty_sha256._VERSION="0.11"
7-
function resty_sha256.update(self, s) end
8-
return resty_sha256
2+
3+
---@class resty.sha256 : resty.string.checksum
4+
local sha256={}
5+
6+
--- Create a new sha256 checksum object.
7+
---@return resty.sha256
8+
function sha256:new() end
9+
10+
return sha256
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---@meta
2-
resty_sha384={}
3-
function resty_sha384.final(self) end
4-
function resty_sha384.new(self) end
5-
function resty_sha384.reset(self) end
6-
resty_sha384._VERSION="0.11"
7-
function resty_sha384.update(self, s) end
8-
return resty_sha384
2+
3+
---@class resty.sha384 : resty.string.checksum
4+
local sha384={}
5+
6+
--- Create a new sha384 checksum object.
7+
---@return resty.sha384
8+
function sha384:new() end
9+
10+
return sha384
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---@meta
2-
resty_sha512={}
3-
function resty_sha512.final(self) end
4-
function resty_sha512.new(self) end
5-
function resty_sha512.reset(self) end
6-
resty_sha512._VERSION="0.11"
7-
function resty_sha512.update(self, s) end
8-
return resty_sha512
2+
3+
---@class resty.sha512 : resty.string.checksum
4+
local sha512={}
5+
6+
--- Create a new sha512 checksum object.
7+
---@return resty.sha512
8+
function sha512:new() end
9+
10+
return sha512
Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,75 @@
11
---@meta
2-
resty_string={}
3-
function resty_string.to_hex(s) end
4-
resty_string._VERSION="0.11"
5-
function resty_string.atoi(s) end
6-
return resty_string
2+
3+
--- OpenResty string functions.
4+
--- https://github.com/openresty/lua-resty-string
5+
local str = {
6+
_VERSION = "0.14",
7+
}
8+
9+
10+
--- Encode byte string in hexidecimal.
11+
---
12+
--- This is most useful for retrieving a printable string from a checksum
13+
--- result.
14+
---
15+
--- Usage:
16+
---
17+
---```lua
18+
--- local str = require "resty.string"
19+
--- local md5 = require "resty.md5"
20+
---
21+
--- local sum = md5:new()
22+
--- sum:update("hello")
23+
--- sum:update("goodbye")
24+
--- local digest = sum:final()
25+
--- print(str.to_hex(digest)) --> 441add4718519b71e42d329a834d6d5e
26+
---```
27+
---@param s string
28+
---@return string hex
29+
function str.to_hex(s) end
30+
31+
--- Convert an ASCII string to an integer.
32+
---
33+
--- If the string is not numeric, `-1` is returned.
34+
---
35+
--- Usage:
36+
---
37+
---```lua
38+
--- local str = require "resty.string"
39+
--- print(str.atoi("250")) --> 250
40+
--- print(str.atoi("abc")) --> -1
41+
---```
42+
---
43+
---@param s string
44+
---@return number
45+
function str.atoi(s) end
46+
47+
48+
--- A lua-resty-string checksum object.
49+
---@class resty.string.checksum : table
50+
local checksum = {
51+
_VERSION = str._VERSION,
52+
}
53+
54+
--- Create a new checksum object.
55+
---@return resty.string.checksum?
56+
function checksum:new() end
57+
58+
--- Add a string to the checksum data.
59+
---
60+
--- This can be called multiple times.
61+
---
62+
---@param s string
63+
---@return boolean ok
64+
function checksum:update(s) end
65+
66+
--- Calculate the final checksum.
67+
---@return string? digest
68+
function checksum:final() end
69+
70+
--- Reset the checksum object.
71+
---@return boolean ok
72+
function checksum:reset() end
73+
74+
75+
return str

0 commit comments

Comments
 (0)