Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to mp4ff v0.46.0 #26

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid breaking change, add a wrapper
  • Loading branch information
hekmon committed Oct 1, 2024
commit 6a5935745419afa989c7988d8c37474101a30464
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
fmt.Printf("type: %s, id: %x, key: %x\n", key.Type, key.ID, key.Key)
}

err = widevine.DecryptMP4(bytes.NewBufferString("encrypted data"),
err = widevine.DecryptMP4Auto(bytes.NewBufferString("encrypted data"),
keys, io.Discard)
if err != nil {
panic(err)
Expand Down
11 changes: 9 additions & 2 deletions decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

// Adapted from https://github.com/Eyevinn/mp4ff/blob/v0.46.0/cmd/mp4ff-decrypt/main.go

// DecryptMP4 decrypts a fragmented MP4 file with keys from widevice license. Supports CENC and CBCS schemes.
func DecryptMP4(r io.Reader, keys []*Key, w io.Writer) error {
// DecryptMP4Auto decrypts a fragmented MP4 file with the set of keys retreived from the widevice license
// by automatically selecting the appropriate key. Supports CENC and CBCS schemes.
func DecryptMP4Auto(r io.Reader, keys []*Key, w io.Writer) error {
// Extract content key
var key []byte
for _, k := range keys {
Expand All @@ -25,6 +26,12 @@ func DecryptMP4(r io.Reader, keys []*Key, w io.Writer) error {
if key == nil {
return fmt.Errorf("no %s key type found in the provided key set", wvpb.License_KeyContainer_CONTENT)
}
// Execute decryption
return DecryptMP4(r, key, w)
}

// DecryptMP4 decrypts a fragmented MP4 file with keys from widevice license. Supports CENC and CBCS schemes.
func DecryptMP4(r io.Reader, key []byte, w io.Writer) error {
// Initialization
inMp4, err := mp4.DecodeFile(r)
if err != nil {
Expand Down
10 changes: 1 addition & 9 deletions decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

wvpb "github.com/iyear/gowidevine/widevinepb"
)

func decodeHex(t require.TestingT, h string) []byte {
Expand Down Expand Up @@ -39,15 +37,9 @@ func TestDecryptMP4(t *testing.T) {
}

for _, tt := range tests {
keySet := []*Key{
{
Type: wvpb.License_KeyContainer_CONTENT,
Key: decodeHex(t, tt.key),
},
}
buf := bytes.NewBuffer(nil)

err := DecryptMP4(bytes.NewReader(readFile(tt.input)), keySet, buf)
err := DecryptMP4(bytes.NewReader(readFile(tt.input)), decodeHex(t, tt.key), buf)
require.NoError(t, err, tt.name)

assert.Equal(t, readFile(tt.expected), buf.Bytes(), tt.name)
Expand Down
Loading