cipher_map_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package qmc
  2. import (
  3. "fmt"
  4. "os"
  5. "reflect"
  6. "testing"
  7. )
  8. func loadTestDataMapCipher(name string) ([]byte, []byte, []byte, error) {
  9. key, err := os.ReadFile(fmt.Sprintf("./testdata/%s_key.bin", name))
  10. if err != nil {
  11. return nil, nil, nil, err
  12. }
  13. raw, err := os.ReadFile(fmt.Sprintf("./testdata/%s_raw.bin", name))
  14. if err != nil {
  15. return nil, nil, nil, err
  16. }
  17. target, err := os.ReadFile(fmt.Sprintf("./testdata/%s_target.bin", name))
  18. if err != nil {
  19. return nil, nil, nil, err
  20. }
  21. return key, raw, target, nil
  22. }
  23. func Test_mapCipher_Decrypt(t *testing.T) {
  24. tests := []struct {
  25. name string
  26. wantErr bool
  27. }{
  28. {"mflac_map", false},
  29. {"mgg_map", false},
  30. }
  31. for _, tt := range tests {
  32. t.Run(tt.name, func(t *testing.T) {
  33. key, raw, target, err := loadTestDataMapCipher(tt.name)
  34. if err != nil {
  35. t.Fatalf("load testing data failed: %s", err)
  36. }
  37. c, err := newMapCipher(key)
  38. if err != nil {
  39. t.Errorf("init mapCipher failed: %s", err)
  40. return
  41. }
  42. c.Decrypt(raw, 0)
  43. if !reflect.DeepEqual(raw, target) {
  44. t.Error("overall")
  45. }
  46. })
  47. }
  48. }