From d4638b782f37729d37c3c8ac942ff87095766173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbjo=CC=88rn=20Einarsson?= Date: Sat, 9 Nov 2024 22:56:34 +0100 Subject: [PATCH] test: extend test of moov for encryption --- mp4/crypto_test.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/mp4/crypto_test.go b/mp4/crypto_test.go index b74433f..a6a5e5b 100644 --- a/mp4/crypto_test.go +++ b/mp4/crypto_test.go @@ -106,18 +106,29 @@ func TestEncryptDecrypt(t *testing.T) { kidHex := "11112222333344445555666677778888" key, _ := hex.DecodeString(keyHex) kidUUID, _ := NewUUIDFromHex(kidHex) + psshFile := "testdata/pssh.bin" + psh, err := os.Open(psshFile) + if err != nil { + t.Fatal(err) + } + box, err := DecodeBox(0, psh) + if err != nil { + t.Fatal(err) + } + pssh := box.(*PsshBox) testCases := []struct { - desc string - init string - seg string - scheme string - iv string + desc string + init string + seg string + scheme string + iv string + hasPssh bool }{ {desc: "video, cenc, iv8", init: videoInit, seg: videoSeg, scheme: "cenc", iv: ivHex8}, {desc: "video, cbcs, iv8", init: videoInit, seg: videoSeg, scheme: "cbcs", iv: ivHex8}, {desc: "video, cbcs, iv16", init: videoInit, seg: videoSeg, scheme: "cbcs", iv: ivHex16}, - {desc: "audio, cbcs, iv16", init: audioInit, seg: audioSeg, scheme: "cbcs", iv: ivHex16}, + {desc: "audio, cbcs, iv16", init: audioInit, seg: audioSeg, scheme: "cbcs", iv: ivHex16, hasPssh: true}, } for _, c := range testCases { t.Run(c.desc, func(t *testing.T) { @@ -134,7 +145,13 @@ func TestEncryptDecrypt(t *testing.T) { if err != nil { t.Fatal(err) } - ipf, err := InitProtect(init.Init, key, iv, c.scheme, kidUUID, nil) + + var psshs []*PsshBox + if c.hasPssh { + psshs = []*PsshBox{pssh} + } + + ipf, err := InitProtect(init.Init, key, iv, c.scheme, kidUUID, psshs) if err != nil { t.Fatal(err) } @@ -254,7 +271,3 @@ func TestDecryptInit(t *testing.T) { } } } - -func TestDecryptEncrypt(t *testing.T) { - -}