forked from moon-source/moonsource-fanqie
✨ 初始提交:月读第三方书源插件集合
每个书源一个独立插件目录,含微信读书公众号订阅、书架导入等完整功能。 Co-authored-by: Copilot <[email protected]>
This commit is contained in:
commit
9190db9019
38 files changed
+5783
No files matched your search
@@ -0,0 +1,36 @@
|
||||
--[[--
|
||||
番茄漫画章节:JSON 页清单 → 页图地址,页图 AES-GCM 解密(只解 CTR 流)。
|
||||
|
||||
@module tests.moonsource_fanqie.comic_spec
|
||||
--]]
|
||||
|
||||
local Assert = require("support.assert")
|
||||
package.preload["json"] = function()
|
||||
local J = require("support.json_stub")
|
||||
return { encode = J.encode, decode = J.decode }
|
||||
end
|
||||
package.loaded["json"] = nil
|
||||
|
||||
local Aes = require("crypto.aes")
|
||||
local Comic = require("moonsource_fanqie.comic")
|
||||
|
||||
local key_hex = string.rep("00", 32)
|
||||
local urls, key = Comic.parse('{"picInfos":[{"picUrl":"https://x/a.jpg?a=1&b=2"},{"picUrl":"https://x/b.jpg"}],'
|
||||
.. '"encrypt":true,"encrypt_key":"' .. key_hex .. '"}')
|
||||
Assert.len(urls, 2)
|
||||
Assert.eq(urls[1], "https://x/a.jpg?a=1&b=2")
|
||||
Assert.eq(urls[2], "https://x/b.jpg")
|
||||
Assert.eq(key, string.rep("\0", 32))
|
||||
|
||||
local _, plain_key = Comic.parse('{"picInfos":[{"picUrl":"https://x/a.jpg"}]}')
|
||||
Assert.is_nil(plain_key)
|
||||
|
||||
Assert.is_nil(Comic.parse("<p>正文</p>"))
|
||||
Assert.is_nil(Comic.parse('{"picInfos":[]}'))
|
||||
|
||||
-- NIST GCM 测试向量 2:全零 128 位密钥与 IV,明文 16 个零字节
|
||||
local iv = string.rep("\0", 12)
|
||||
local sealed = iv .. Aes.from_hex("0388dace60b6a392f328c2b971b2fe78" .. "ab6e47d42cec13bdf53a67b21257bddf")
|
||||
Assert.eq(Comic.decrypt(sealed, string.rep("\0", 16)), string.rep("\0", 16))
|
||||
Assert.eq(Comic.decrypt("raw", nil), "raw")
|
||||
Assert.is_nil(Comic.decrypt("short", string.rep("\0", 16)))
|
||||
Reference in new issue
Block a user