Skip to content

Commit

Permalink
chore(style): golangci-lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Oct 25, 2023
1 parent e1976dd commit 276453e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
17 changes: 11 additions & 6 deletions decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ package widevine
import (
"bytes"
"fmt"
"github.com/Eyevinn/mp4ff/mp4"
"io"

"github.com/Eyevinn/mp4ff/mp4"
)

const (
schemeCENC = "cenc"
schemeCBCS = "cbcs"
)

func DecryptMP4(r io.Reader, key []byte, w io.Writer) error {
Expand Down Expand Up @@ -56,7 +62,7 @@ func DecryptMP4(r io.Reader, key []byte, w io.Writer) error {
continue
}
}
if schemeType != "" && schemeType != "cenc" && schemeType != "cbcs" {
if schemeType != "" && schemeType != schemeCENC && schemeType != schemeCBCS {
return fmt.Errorf("scheme type %s not supported", schemeType)
}
if schemeType == "" {
Expand Down Expand Up @@ -146,7 +152,7 @@ func decryptFragment(frag *mp4.Fragment, tracks []trackInfo, key []byte) error {
ti := findTrackInfo(tracks, traf.Tfhd.TrackID)
if ti.sinf != nil {
schemeType := ti.sinf.Schm.SchemeType
if schemeType != "cenc" && schemeType != "cbcs" {
if schemeType != schemeCENC && schemeType != schemeCBCS {
return fmt.Errorf("scheme type %s not supported", schemeType)
}
hasSenc, isParsed := traf.ContainsSencBox()
Expand Down Expand Up @@ -188,7 +194,6 @@ func decryptFragment(frag *mp4.Fragment, tracks []trackInfo, key []byte) error {

// decryptSample - decrypt samples inplace
func decryptSamplesInPlace(schemeType string, samples []mp4.FullSample, key []byte, tenc *mp4.TencBox, senc *mp4.SencBox) error {

// TODO. Interpret saio and saiz to get to the right place
// Saio tells where the IV starts relative to moof start
// It typically ends up inside senc (16 bytes after start)
Expand Down Expand Up @@ -216,12 +221,12 @@ func decryptSamplesInPlace(schemeType string, samples []mp4.FullSample, key []by
subSamplePatterns = senc.SubSamples[i]
}
switch schemeType {
case "cenc":
case schemeCENC:
err := mp4.DecryptSampleCenc(encSample, key, iv, subSamplePatterns)
if err != nil {
return err
}
case "cbcs":
case schemeCBCS:
err := mp4.DecryptSampleCbcs(encSample, key, iv, subSamplePatterns, tenc)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package widevine
import (
"bytes"
"encoding/hex"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"testing"

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

func decodeHex(t require.TestingT, h string) []byte {
Expand Down
2 changes: 1 addition & 1 deletion device.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func toDevice(clientID, privateKey []byte) (*Device, error) {

// parsePrivateKey modified from https://go.dev/src/crypto/tls/tls.go#L339
func parsePrivateKey(data []byte) (*rsa.PrivateKey, error) {
var b = make([]byte, len(data))
b := make([]byte, len(data))
copy(b, data)

if bytes.HasPrefix(data, []byte("-----")) {
Expand Down
5 changes: 3 additions & 2 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package widevine
import (
"bytes"
_ "embed"
wvpb "github.com/iyear/gowidevine/widevinepb"
"github.com/stretchr/testify/require"
"testing"

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

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

//go:embed testdata/device/client_id
Expand Down

0 comments on commit 276453e

Please sign in to comment.