test(QMCv2): add case mflac_rc4

pull/29/head
MengYX 3 years ago
parent def2925900
commit 42d658625f
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604

@ -6,16 +6,17 @@ import (
"testing"
)
func loadTestRC4CipherData() ([]byte, []byte, []byte, error) {
key, err := os.ReadFile("./testdata/mflac0_rc4_key.bin")
func loadTestRC4CipherData(name string) ([]byte, []byte, []byte, error) {
prefix := "./testdata/" + name
key, err := os.ReadFile(prefix + "_key.bin")
if err != nil {
return nil, nil, nil, err
}
raw, err := os.ReadFile("./testdata/mflac0_rc4_raw.bin")
raw, err := os.ReadFile(prefix + "_raw.bin")
if err != nil {
return nil, nil, nil, err
}
target, err := os.ReadFile("./testdata/mflac0_rc4_target.bin")
target, err := os.ReadFile(prefix + "_target.bin")
if err != nil {
return nil, nil, nil, err
}
@ -23,25 +24,34 @@ func loadTestRC4CipherData() ([]byte, []byte, []byte, error) {
return key, raw, target, nil
}
func Test_rc4Cipher_Decrypt(t *testing.T) {
key, raw, target, err := loadTestRC4CipherData()
if err != nil {
t.Fatalf("load testing data failed: %s", err)
tests := []struct {
name string
wantErr bool
}{
{"mflac0_rc4", false},
{"mflac_rc4", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
key, raw, target, err := loadTestRC4CipherData(tt.name)
if err != nil {
t.Fatalf("load testing data failed: %s", err)
}
c, err := NewRC4Cipher(key)
if err != nil {
t.Errorf("init rc4Cipher failed: %s", err)
return
}
c.Decrypt(raw, 0)
if !reflect.DeepEqual(raw, target) {
t.Error("overall")
}
})
}
t.Run("overall", func(t *testing.T) {
c, err := NewRC4Cipher(key)
if err != nil {
t.Errorf("init rc4Cipher failed: %s", err)
return
}
c.Decrypt(raw, 0)
if !reflect.DeepEqual(raw, target) {
t.Error("overall")
}
})
}
func BenchmarkRc4Cipher_Decrypt(b *testing.B) {
key, raw, _, err := loadTestRC4CipherData()
key, raw, _, err := loadTestRC4CipherData("mflac0_rc4")
if err != nil {
b.Fatalf("load testing data failed: %s", err)
}
@ -57,7 +67,7 @@ func BenchmarkRc4Cipher_Decrypt(b *testing.B) {
}
func Test_rc4Cipher_encFirstSegment(t *testing.T) {
key, raw, target, err := loadTestRC4CipherData()
key, raw, target, err := loadTestRC4CipherData("mflac0_rc4")
if err != nil {
t.Fatalf("load testing data failed: %s", err)
}
@ -75,7 +85,7 @@ func Test_rc4Cipher_encFirstSegment(t *testing.T) {
}
func Test_rc4Cipher_encASegment(t *testing.T) {
key, raw, target, err := loadTestRC4CipherData()
key, raw, target, err := loadTestRC4CipherData("mflac0_rc4")
if err != nil {
t.Fatalf("load testing data failed: %s", err)
}

@ -27,7 +27,6 @@ func loadDecryptKeyData(name string) ([]byte, []byte, error) {
return keyRaw, keyDec, nil
}
func TestDecryptKey(t *testing.T) {
tests := []struct {
name string
filename string
@ -35,13 +34,15 @@ func TestDecryptKey(t *testing.T) {
}{
{"mflac0_rc4(512)", "mflac0_rc4", false},
{"mflac_map(256)", "mflac_map", false},
{"mflac_rc4(256)", "mflac_rc4", false},
{"mgg_map(256)", "mgg_map", false},
}
for _, tt := range tests {
raw, want, err := loadDecryptKeyData(tt.filename)
if err != nil {
t.Fatalf("load test data failed: %s", err)
}
t.Run(tt.name, func(t *testing.T) {
raw, want, err := loadDecryptKeyData(tt.filename)
if err != nil {
t.Fatalf("load test data failed: %s", err)
}
got, err := DecryptKey(raw)
if (err != nil) != tt.wantErr {
t.Errorf("DecryptKey() error = %v, wantErr %v", err, tt.wantErr)

@ -32,6 +32,7 @@ func TestMflac0Decoder_Read(t *testing.T) {
wantErr bool
}{
{"mflac0_rc4", false},
{"mflac_rc4", false},
{"mflac_map", false},
{"mgg_map", false},
{"qmc0_static", false},

@ -0,0 +1 @@
pUtyvqr0TgAvR95mNmY7DmNl386TsJNAEIz95CEcgIgJCcs28686O7llxD5E74ldn70xMtd5cG58TA5ILw09I8BOTf5EdHKd6wwPn689DUK13y3Req6H0P33my2miJ5bQ2AA22B8vp4V0NJ3hBqNtFf7cId48V6W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Binary file not shown.
Loading…
Cancel
Save