MCPcopy
hub / github.com/OpenNHP/opennhp / FuzzAESDecrypt

Function FuzzAESDecrypt

nhp/test/fuzz_test.go:42–62  ·  view source on GitHub ↗

FuzzAESDecrypt tests AES decryption with random inputs. Ensures malformed ciphertext is handled without panics.

(f *testing.F)

Source from the content-addressed store, hash-verified

40// FuzzAESDecrypt tests AES decryption with random inputs.
41// Ensures malformed ciphertext is handled without panics.
42func FuzzAESDecrypt(f *testing.F) {
43 // Seed corpus with various sizes
44 f.Add(make([]byte, 16), make([]byte, 32)) // minimum block size
45 f.Add(make([]byte, 32), make([]byte, 32)) // two blocks
46 f.Add(make([]byte, 48), make([]byte, 32)) // three blocks
47 f.Add([]byte{}, make([]byte, 32)) // empty ciphertext
48
49 f.Fuzz(func(t *testing.T, ciphertext []byte, key []byte) {
50 // Normalize key to 32 bytes (AES-256)
51 if len(key) < 32 {
52 paddedKey := make([]byte, 32)
53 copy(paddedKey, key)
54 key = paddedKey
55 } else if len(key) > 32 {
56 key = key[:32]
57 }
58
59 // AESDecrypt should not panic on any input
60 _, _ = core.AESDecrypt(ciphertext, key)
61 })
62}
63
64// FuzzHeaderTypeToDeviceType tests header type to device type mapping.
65func FuzzHeaderTypeToDeviceType(f *testing.F) {

Callers

nothing calls this directly

Calls 1

AddMethod · 0.65

Tested by

no test coverage detected