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 {
|
||||
return fmt.Sprintf("error while stopping due to %s: %s",
|
||||
sprintErr(e.Cause), sprintErr(e.Err),
|
||||
)
|
||||
return fmt.Sprintf("error while stopping due to %s: %s", sprintErr(e.Cause), sprintErr(e.Err))
|
||||
}
|
||||
|
||||
// CloseErr indicates client close failure.
|
||||
@@ -294,9 +292,7 @@ func sprintErr(err error) string {
|
||||
}
|
||||
|
||||
func (c CloseErr) Error() string {
|
||||
return fmt.Sprintf("failed to close: %s (connection), %s (agent)",
|
||||
sprintErr(c.ConnectionErr), sprintErr(c.AgentErr),
|
||||
)
|
||||
return fmt.Sprintf("failed to close: %s (connection), %s (agent)", sprintErr(c.ConnectionErr), sprintErr(c.AgentErr))
|
||||
}
|
||||
|
||||
func (c *Client) readUntilClosed() {
|
||||
|
@@ -16,14 +16,7 @@ const credentialsSep = ":"
|
||||
// NewLongTermIntegrity returns new MessageIntegrity with key for long-term
|
||||
// credentials. Password, username, and realm must be SASL-prepared.
|
||||
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity {
|
||||
k := strings.Join(
|
||||
[]string{
|
||||
username,
|
||||
realm,
|
||||
password,
|
||||
},
|
||||
credentialsSep,
|
||||
)
|
||||
k := strings.Join([]string{username, realm, password}, credentialsSep)
|
||||
// #nosec
|
||||
h := md5.New()
|
||||
fmt.Fprint(h, k)
|
||||
|
28
message.go
28
message.go
@@ -93,12 +93,8 @@ func (m *Message) NewTransactionID() error {
|
||||
}
|
||||
|
||||
func (m *Message) String() string {
|
||||
return fmt.Sprintf("%s l=%d attrs=%d id=%s",
|
||||
m.Type,
|
||||
m.Length,
|
||||
len(m.Attributes),
|
||||
base64.StdEncoding.EncodeToString(m.TransactionID[:]),
|
||||
)
|
||||
tID := base64.StdEncoding.EncodeToString(m.TransactionID[:])
|
||||
return fmt.Sprintf("%s l=%d attrs=%d id=%s", m.Type, m.Length, len(m.Attributes), tID)
|
||||
}
|
||||
|
||||
// Reset resets Message, attributes and underlying buffer length.
|
||||
@@ -336,17 +332,11 @@ func (m *Message) Decode() error {
|
||||
fullSize = messageHeaderSize + size // len(m.Raw)
|
||||
)
|
||||
if cookie != magicCookie {
|
||||
msg := fmt.Sprintf(
|
||||
"%x is invalid magic cookie (should be %x)",
|
||||
cookie, magicCookie,
|
||||
)
|
||||
msg := fmt.Sprintf("%x is invalid magic cookie (should be %x)", cookie, magicCookie)
|
||||
return newDecodeErr("message", "cookie", msg)
|
||||
}
|
||||
if len(buf) < fullSize {
|
||||
msg := fmt.Sprintf(
|
||||
"buffer length %d is less than %d (expected message size)",
|
||||
len(buf), fullSize,
|
||||
)
|
||||
msg := fmt.Sprintf("buffer length %d is less than %d (expected message size)", len(buf), fullSize)
|
||||
return newAttrDecodeErr("message", msg)
|
||||
}
|
||||
// saving header data
|
||||
@@ -362,10 +352,7 @@ func (m *Message) Decode() error {
|
||||
for offset < size {
|
||||
// checking that we have enough bytes to read header
|
||||
if len(b) < attributeHeaderSize {
|
||||
msg := fmt.Sprintf(
|
||||
"buffer length %d is less than %d (expected header size)",
|
||||
len(b), attributeHeaderSize,
|
||||
)
|
||||
msg := fmt.Sprintf("buffer length %d is less than %d (expected header size)", len(b), attributeHeaderSize)
|
||||
return newAttrDecodeErr("header", msg)
|
||||
}
|
||||
var (
|
||||
@@ -379,10 +366,7 @@ func (m *Message) Decode() error {
|
||||
b = b[attributeHeaderSize:] // slicing again to simplify value read
|
||||
offset += attributeHeaderSize
|
||||
if len(b) < aBuffL { // checking size
|
||||
msg := fmt.Sprintf(
|
||||
"buffer length %d is less than %d (expected value size for %s)",
|
||||
len(b), aBuffL, a.Type,
|
||||
)
|
||||
msg := fmt.Sprintf("buffer length %d is less than %d (expected value size for %s)", len(b), aBuffL, a.Type)
|
||||
return newAttrDecodeErr("value", msg)
|
||||
}
|
||||
a.Value = b[:aL]
|
||||
|
Reference in New Issue
Block a user