Skip to content

Commit

Permalink
test: extend test of moov for encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Nov 9, 2024
1 parent 15e1b55 commit d4638b7
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions mp4/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -254,7 +271,3 @@ func TestDecryptInit(t *testing.T) {
}
}
}

func TestDecryptEncrypt(t *testing.T) {

}

0 comments on commit d4638b7

Please sign in to comment.