Files
ice/stun.go
Aleksandr Razumov d895187fa4 Prepare for stun v2
Using github.com/gortc/stun for now.
Should be easy to change it later.
2019-05-21 15:53:04 -07:00

29 lines
633 B
Go

package ice
import (
"encoding/binary"
"fmt"
"github.com/gortc/stun"
)
// bin is shorthand for BigEndian.
var bin = binary.BigEndian
func assertInboundUsername(m *stun.Message, expectedUsername string) error {
var username stun.Username
if err := username.GetFrom(m); err != nil {
return err
}
if string(username) != expectedUsername {
return fmt.Errorf("username mismatch expected(%x) actual(%x)", expectedUsername, string(username))
}
return nil
}
func assertInboundMessageIntegrity(m *stun.Message, key []byte) error {
messageIntegrityAttr := stun.MessageIntegrity(key)
return messageIntegrityAttr.Check(m)
}