发布 0.3.0 并增加 RSA 签名验证

This commit is contained in:
mid
2026-08-13 13:32:56 +08:00
parent 32b7cc827c
commit 0ae6db36cb
27 changed files with 2025 additions and 274 deletions
+15
View File
@@ -7,6 +7,7 @@ import {
formatBytes,
parseHex,
textToBytes,
textToBytesLimited,
} from '../src/lib/bytes'
describe('parseHex', () => {
@@ -25,6 +26,20 @@ describe('parseHex', () => {
expect(() => parseHex('AA0xBB')).toThrow('无效')
expect(() => parseHex('ABC')).toThrow('偶数')
expect(() => parseHex('0011', 16)).toThrow('当前为 2 字节')
expect(() => parseHex(',AA')).toThrow('片段缺少')
expect(() => parseHex('AA,')).toThrow('片段缺少')
})
it('supports bounded parsing without allocating oversized output', () => {
expect(parseHex('00 11', { maxBytes: 2 })).toEqual(Uint8Array.from([0, 0x11]))
expect(() => parseHex('00 11 22', { maxBytes: 2, limitLabel: '测试数据' })).toThrow('测试数据不能超过')
expect(() => parseHex('0'.repeat(2_000), { maxInputChars: 100 })).toThrow('输入不能超过')
})
it('encodes bounded UTF-8 text before allocating the result', () => {
expect(textToBytesLimited('你好', 6)).toEqual(textToBytes('你好'))
expect(() => textToBytesLimited('你好', 5)).toThrow('不能超过 5 字节')
expect(() => textToBytesLimited('abc', 10, 2, '测试数据')).toThrow('输入不能超过')
})
})