2021-12-13 14:54:08 +00:00
|
|
|
package qmc
|
|
|
|
|
|
|
|
import (
|
2021-12-13 18:56:33 +00:00
|
|
|
"fmt"
|
2021-12-13 14:54:08 +00:00
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-12-13 18:56:33 +00:00
|
|
|
func loadTestDataMapCipher(name string) ([]byte, []byte, []byte, error) {
|
|
|
|
key, err := os.ReadFile(fmt.Sprintf("./testdata/%s_key.bin", name))
|
2021-12-13 14:54:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
2021-12-13 18:56:33 +00:00
|
|
|
raw, err := os.ReadFile(fmt.Sprintf("./testdata/%s_raw.bin", name))
|
2021-12-13 14:54:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
2021-12-13 18:56:33 +00:00
|
|
|
target, err := os.ReadFile(fmt.Sprintf("./testdata/%s_target.bin", name))
|
2021-12-13 14:54:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
|
|
|
return key, raw, target, nil
|
|
|
|
}
|
|
|
|
func Test_mapCipher_Decrypt(t *testing.T) {
|
2021-12-13 18:56:33 +00: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-18 23:25:42 +00:00
|
|
|
c, err := newMapCipher(key)
|
2021-12-13 18:56:33 +00: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 14:54:08 +00:00
|
|
|
}
|
|
|
|
}
|