发布 0.3.0 并增加 RSA 签名验证
This commit is contained in:
@@ -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('输入不能超过')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user