mirror of
				https://git.unlock-music.dev/um/web.git
				synced 2025-11-04 08:03:29 +08:00 
			
		
		
		
	test(QMCv2): coverage standard TEA cipher
(cherry picked from commit c2c89a423ffffc06fb43c86d4714bb32d1936c3e)
This commit is contained in:
		
							parent
							
								
									769d3392f8
								
							
						
					
					
						commit
						8c11f47aa4
					
				@ -6,6 +6,7 @@
 | 
			
		||||
 | 
			
		||||
import {TeaCipher} from "@/utils/tea";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
test("key size", () => {
 | 
			
		||||
    const testKey = new Uint8Array([
 | 
			
		||||
        0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
 | 
			
		||||
@ -52,6 +53,12 @@ const teaTests = [
 | 
			
		||||
    },
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
test("rounds", () => {
 | 
			
		||||
    const tt = teaTests[0];
 | 
			
		||||
    expect(() => new TeaCipher(tt.key, tt.rounds - 1))
 | 
			
		||||
        .toThrow()
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
test("encrypt & decrypt", () => {
 | 
			
		||||
    for (const tt of teaTests) {
 | 
			
		||||
@ -67,3 +74,4 @@ test("encrypt & decrypt", () => {
 | 
			
		||||
        expect(buf).toStrictEqual(tt.plainText)
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -51,9 +51,6 @@ export class TeaCipher {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    encrypt(dst: DataView, src: DataView) {
 | 
			
		||||
        if (src.byteLength != 8) {
 | 
			
		||||
            throw Error("src.byteLength != 8")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let v0 = src.getUint32(0, false)
 | 
			
		||||
        let v1 = src.getUint32(4, false)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user