Add bambu-nfc dump parse, Key-A HKDF, and spool merge.
Parse filanfc-dump/v1 zip/JSON, Bambu 1K images, and merge stickers by tray UID. dump and mifare packages stay importable for a later common library.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package dump
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseJSONFixture(t *testing.T) {
|
||||
t.Parallel()
|
||||
f, err := os.Open(filepath.Join("..", "testdata", "dumps", "e27be276.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
d, err := ParseJSON(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if d.ChipUID != "e27be276" {
|
||||
t.Errorf("ChipUID = %q", d.ChipUID)
|
||||
}
|
||||
if d.Format != FormatV1 {
|
||||
t.Errorf("Format = %q", d.Format)
|
||||
}
|
||||
if len(d.Image) != 1024 {
|
||||
t.Errorf("Image len = %d", len(d.Image))
|
||||
}
|
||||
if len(d.SectorsFail) != 0 {
|
||||
t.Errorf("SectorsFail = %v", d.SectorsFail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseZipFixture(t *testing.T) {
|
||||
t.Parallel()
|
||||
f, err := os.Open(filepath.Join("..", "testdata", "dumps.zip"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
dumps, err := ParseZip(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(dumps) != 6 {
|
||||
t.Errorf("len = %d; want 6", len(dumps))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseJSONRejectsBadFormat(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := ParseJSON(strings.NewReader(`{"format":"nope","chip_uid":"aa","dump_hex":"` + strings.Repeat("00", 1024) + `"}`))
|
||||
if !errors.Is(err, ErrInvalidDump) {
|
||||
t.Fatalf("err = %v; want ErrInvalidDump", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user