Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion data_psi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package astits

import (
"errors"
"fmt"

"github.com/asticode/go-astikit"
Expand Down Expand Up @@ -46,6 +47,8 @@ const (
PSITableIDNITVariant2 PSITableID = 0x41
)

var ErrCRC32Mismatch = errors.New("astits: CRC32 mismatch")

// PSIData represents a PSI data
// https://en.wikipedia.org/wiki/Program-specific_information
type PSIData struct {
Expand Down Expand Up @@ -175,7 +178,7 @@ func parsePSISection(i *astikit.BytesIterator) (s *PSISection, stop bool, err er

// Check CRC32
if crc32 != s.CRC32 {
err = fmt.Errorf("astits: Table CRC32 %x != computed CRC32 %x", s.CRC32, crc32)
err = errors.Join(ErrCRC32Mismatch, fmt.Errorf("astits: Table CRC32 %x != computed CRC32 %x", s.CRC32, crc32))
return
}
}
Expand Down
4 changes: 3 additions & 1 deletion data_psi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package astits

import (
"bytes"
"errors"
"testing"

"github.com/asticode/go-astikit"
Expand Down Expand Up @@ -168,7 +169,8 @@ func TestParsePSIData(t *testing.T) {
w.Write(totBytes()) // TOT data
w.Write(uint32(32)) // TOT CRC32
_, err := parsePSIData(astikit.NewBytesIterator(buf.Bytes()))
assert.EqualError(t, err, "astits: parsing PSI table failed: astits: Table CRC32 20 != computed CRC32 6969b13")
assert.True(t, errors.Is(err, ErrCRC32Mismatch))
assert.Equal(t, "astits: parsing PSI table failed: astits: CRC32 mismatch\nastits: Table CRC32 20 != computed CRC32 6969b13", err.Error())

// Valid
d, err := parsePSIData(astikit.NewBytesIterator(psiBytes()))
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
module github.com/asticode/go-astits

go 1.13
go 1.20

require (
github.com/asticode/go-astikit v0.30.0
github.com/pkg/profile v1.4.0
github.com/stretchr/testify v1.4.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
Loading