github.com/amnezia-vpn/amnezia-wg@v0.1.8/device/util.go (about) 1 package device 2 3 import ( 4 "bytes" 5 crand "crypto/rand" 6 "fmt" 7 ) 8 9 func appendJunk(writer *bytes.Buffer, size int) error { 10 headerJunk, err := randomJunkWithSize(size) 11 if err != nil { 12 return fmt.Errorf("failed to create header junk: %v", err) 13 } 14 _, err = writer.Write(headerJunk) 15 if err != nil { 16 return fmt.Errorf("failed to write header junk: %v", err) 17 } 18 return nil 19 } 20 21 func randomJunkWithSize(size int) ([]byte, error) { 22 junk := make([]byte, size) 23 _, err := crand.Read(junk) 24 return junk, err 25 }