mirror of
https://github.com/gortc/stun.git
synced 2025-09-26 20:41:36 +08:00
all: reduce newline overuse
This commit is contained in:
@@ -275,9 +275,7 @@ type StopErr struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e StopErr) Error() string {
|
func (e StopErr) Error() string {
|
||||||
return fmt.Sprintf("error while stopping due to %s: %s",
|
return fmt.Sprintf("error while stopping due to %s: %s", sprintErr(e.Cause), sprintErr(e.Err))
|
||||||
sprintErr(e.Cause), sprintErr(e.Err),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloseErr indicates client close failure.
|
// CloseErr indicates client close failure.
|
||||||
@@ -294,9 +292,7 @@ func sprintErr(err error) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c CloseErr) Error() string {
|
func (c CloseErr) Error() string {
|
||||||
return fmt.Sprintf("failed to close: %s (connection), %s (agent)",
|
return fmt.Sprintf("failed to close: %s (connection), %s (agent)", sprintErr(c.ConnectionErr), sprintErr(c.AgentErr))
|
||||||
sprintErr(c.ConnectionErr), sprintErr(c.AgentErr),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) readUntilClosed() {
|
func (c *Client) readUntilClosed() {
|
||||||
|
@@ -16,14 +16,7 @@ const credentialsSep = ":"
|
|||||||
// NewLongTermIntegrity returns new MessageIntegrity with key for long-term
|
// NewLongTermIntegrity returns new MessageIntegrity with key for long-term
|
||||||
// credentials. Password, username, and realm must be SASL-prepared.
|
// credentials. Password, username, and realm must be SASL-prepared.
|
||||||
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity {
|
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity {
|
||||||
k := strings.Join(
|
k := strings.Join([]string{username, realm, password}, credentialsSep)
|
||||||
[]string{
|
|
||||||
username,
|
|
||||||
realm,
|
|
||||||
password,
|
|
||||||
},
|
|
||||||
credentialsSep,
|
|
||||||
)
|
|
||||||
// #nosec
|
// #nosec
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
fmt.Fprint(h, k)
|
fmt.Fprint(h, k)
|
||||||
|
28
message.go
28
message.go
@@ -93,12 +93,8 @@ func (m *Message) NewTransactionID() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) String() string {
|
func (m *Message) String() string {
|
||||||
return fmt.Sprintf("%s l=%d attrs=%d id=%s",
|
tID := base64.StdEncoding.EncodeToString(m.TransactionID[:])
|
||||||
m.Type,
|
return fmt.Sprintf("%s l=%d attrs=%d id=%s", m.Type, m.Length, len(m.Attributes), tID)
|
||||||
m.Length,
|
|
||||||
len(m.Attributes),
|
|
||||||
base64.StdEncoding.EncodeToString(m.TransactionID[:]),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset resets Message, attributes and underlying buffer length.
|
// Reset resets Message, attributes and underlying buffer length.
|
||||||
@@ -336,17 +332,11 @@ func (m *Message) Decode() error {
|
|||||||
fullSize = messageHeaderSize + size // len(m.Raw)
|
fullSize = messageHeaderSize + size // len(m.Raw)
|
||||||
)
|
)
|
||||||
if cookie != magicCookie {
|
if cookie != magicCookie {
|
||||||
msg := fmt.Sprintf(
|
msg := fmt.Sprintf("%x is invalid magic cookie (should be %x)", cookie, magicCookie)
|
||||||
"%x is invalid magic cookie (should be %x)",
|
|
||||||
cookie, magicCookie,
|
|
||||||
)
|
|
||||||
return newDecodeErr("message", "cookie", msg)
|
return newDecodeErr("message", "cookie", msg)
|
||||||
}
|
}
|
||||||
if len(buf) < fullSize {
|
if len(buf) < fullSize {
|
||||||
msg := fmt.Sprintf(
|
msg := fmt.Sprintf("buffer length %d is less than %d (expected message size)", len(buf), fullSize)
|
||||||
"buffer length %d is less than %d (expected message size)",
|
|
||||||
len(buf), fullSize,
|
|
||||||
)
|
|
||||||
return newAttrDecodeErr("message", msg)
|
return newAttrDecodeErr("message", msg)
|
||||||
}
|
}
|
||||||
// saving header data
|
// saving header data
|
||||||
@@ -362,10 +352,7 @@ func (m *Message) Decode() error {
|
|||||||
for offset < size {
|
for offset < size {
|
||||||
// checking that we have enough bytes to read header
|
// checking that we have enough bytes to read header
|
||||||
if len(b) < attributeHeaderSize {
|
if len(b) < attributeHeaderSize {
|
||||||
msg := fmt.Sprintf(
|
msg := fmt.Sprintf("buffer length %d is less than %d (expected header size)", len(b), attributeHeaderSize)
|
||||||
"buffer length %d is less than %d (expected header size)",
|
|
||||||
len(b), attributeHeaderSize,
|
|
||||||
)
|
|
||||||
return newAttrDecodeErr("header", msg)
|
return newAttrDecodeErr("header", msg)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
@@ -379,10 +366,7 @@ func (m *Message) Decode() error {
|
|||||||
b = b[attributeHeaderSize:] // slicing again to simplify value read
|
b = b[attributeHeaderSize:] // slicing again to simplify value read
|
||||||
offset += attributeHeaderSize
|
offset += attributeHeaderSize
|
||||||
if len(b) < aBuffL { // checking size
|
if len(b) < aBuffL { // checking size
|
||||||
msg := fmt.Sprintf(
|
msg := fmt.Sprintf("buffer length %d is less than %d (expected value size for %s)", len(b), aBuffL, a.Type)
|
||||||
"buffer length %d is less than %d (expected value size for %s)",
|
|
||||||
len(b), aBuffL, a.Type,
|
|
||||||
)
|
|
||||||
return newAttrDecodeErr("value", msg)
|
return newAttrDecodeErr("value", msg)
|
||||||
}
|
}
|
||||||
a.Value = b[:aL]
|
a.Value = b[:aL]
|
||||||
|
@@ -56,9 +56,7 @@ func (a *UnknownAttributes) GetFrom(m *Message) error {
|
|||||||
first := 0
|
first := 0
|
||||||
for first < len(v) {
|
for first < len(v) {
|
||||||
last := first + attrTypeSize
|
last := first + attrTypeSize
|
||||||
*a = append(*a,
|
*a = append(*a, AttrType(bin.Uint16(v[first:last])))
|
||||||
AttrType(bin.Uint16(v[first:last])),
|
|
||||||
)
|
|
||||||
first = last
|
first = last
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user