init
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Package comms validates the data that crosses the wormhole link. The
|
||||
// content of uplinks and downlinks is opaque bytes defined by the player's
|
||||
// ship program; only sizes are enforced.
|
||||
package comms
|
||||
|
||||
import "fmt"
|
||||
|
||||
func CheckUplink(data []byte, limit int) error {
|
||||
if len(data) > limit {
|
||||
return fmt.Errorf("uplink is %d bytes, limit is %d", len(data), limit)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckProgram(prog []byte, limit int) error {
|
||||
switch {
|
||||
case len(prog) == 0:
|
||||
return fmt.Errorf("program is empty")
|
||||
case len(prog)%4 != 0:
|
||||
return fmt.Errorf("program length %d is not a multiple of 4", len(prog))
|
||||
case len(prog) > limit:
|
||||
return fmt.Errorf("program is %d bytes, limit is %d", len(prog), limit)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user