checks.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // +build !debug
  2. package stun
  3. import "github.com/pion/stun/internal/hmac"
  4. // CheckSize returns ErrAttrSizeInvalid if got is not equal to expected.
  5. func CheckSize(_ AttrType, got, expected int) error {
  6. if got == expected {
  7. return nil
  8. }
  9. return ErrAttributeSizeInvalid
  10. }
  11. func checkHMAC(got, expected []byte) error {
  12. if hmac.Equal(got, expected) {
  13. return nil
  14. }
  15. return ErrIntegrityMismatch
  16. }
  17. func checkFingerprint(got, expected uint32) error {
  18. if got == expected {
  19. return nil
  20. }
  21. return ErrFingerprintMismatch
  22. }
  23. // IsAttrSizeInvalid returns true if error means that attribute size is invalid.
  24. func IsAttrSizeInvalid(err error) bool {
  25. return err == ErrAttributeSizeInvalid
  26. }
  27. // CheckOverflow returns ErrAttributeSizeOverflow if got is bigger that max.
  28. func CheckOverflow(_ AttrType, got, max int) error {
  29. if got <= max {
  30. return nil
  31. }
  32. return ErrAttributeSizeOverflow
  33. }
  34. // IsAttrSizeOverflow returns true if error means that attribute size is too big.
  35. func IsAttrSizeOverflow(err error) bool {
  36. return err == ErrAttributeSizeOverflow
  37. }