This repository has been archived by the owner on Jun 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attrs: add CheckOverflow and IsAttrSizeOverflow
- Loading branch information
Showing
15 changed files
with
125 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// +build debug | ||
|
||
package stun | ||
|
||
import "fmt" | ||
|
||
// AttrOverflowErr occurs when len(v) > Max. | ||
type AttrOverflowErr struct { | ||
Type AttrType | ||
Max int | ||
Got int | ||
} | ||
|
||
func (e AttrOverflowErr) Error() string { | ||
return fmt.Sprintf("incorrect length of %s attribute: %d exceeds maximum %d", | ||
e.Type, e.Got, e.Max, | ||
) | ||
} | ||
|
||
// AttrLengthErr means that length for attribute is invalid. | ||
type AttrLengthErr struct { | ||
Attr AttrType | ||
Got int | ||
Expected int | ||
} | ||
|
||
func (e AttrLengthErr) Error() string { | ||
return fmt.Sprintf("incorrect length of %s attribute: got %d, expected %d", | ||
e.Attr, | ||
e.Got, | ||
e.Expected, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// +build debug | ||
|
||
package stun | ||
|
||
import "testing" | ||
|
||
func TestAttrOverflowErr_Error(t *testing.T) { | ||
err := AttrOverflowErr{ | ||
Got: 100, | ||
Max: 50, | ||
Type: AttrLifetime, | ||
} | ||
if err.Error() != "incorrect length of LIFETIME attribute: 100 exceeds maximum 50" { | ||
t.Error("bad error string", err) | ||
} | ||
} | ||
|
||
func TestAttrLengthErr_Error(t *testing.T) { | ||
err := AttrLengthErr{ | ||
Attr: AttrErrorCode, | ||
Expected: 15, | ||
Got: 99, | ||
} | ||
if err.Error() != "incorrect length of ERROR-CODE attribute: got 99, expected 15" { | ||
t.Errorf("bad error string: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters