2021-12-13 22:54:08 +08:00
|
|
|
package qmc
|
|
|
|
|
|
|
|
import (
|
2021-12-14 02:56:33 +08:00
|
|
|
"fmt"
|
2021-12-13 22:54:08 +08:00
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-12-14 02:56:33 +08:00
|
|
|
func loadTestDataMapCipher(name string) ([]byte, []byte, []byte, error) {
|
|
|
|
key, err := os.ReadFile(fmt.Sprintf("./testdata/%s_key.bin", name))
|
2021-12-13 22:54:08 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
2021-12-14 02:56:33 +08:00
|
|
|
raw, err := os.ReadFile(fmt.Sprintf("./testdata/%s_raw.bin", name))
|
2021-12-13 22:54:08 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
2021-12-14 02:56:33 +08:00
|
|
|
target, err := os.ReadFile(fmt.Sprintf("./testdata/%s_target.bin", name))
|
2021-12-13 22:54:08 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
|
|
|
return key, raw, target, nil
|
|
|
|
}
|
|
|
|
func Test_mapCipher_Decrypt(t *testing.T) {
|
2021-12-14 02:56:33 +08:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{"mflac_map", false},
|
|
|
|
{"mgg_map", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
key, raw, target, err := loadTestDataMapCipher(tt.name)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("load testing data failed: %s", err)
|
|
|
|
}
|
2022-11-19 07:25:42 +08:00
|
|
|
c, err := newMapCipher(key)
|
2021-12-14 02:56:33 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("init mapCipher failed: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Decrypt(raw, 0)
|
|
|
|
if !reflect.DeepEqual(raw, target) {
|
|
|
|
t.Error("overall")
|
|
|
|
}
|
|
|
|
})
|
2021-12-13 22:54:08 +08:00
|
|
|
}
|
|
|
|
}
|