mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 21:40:45 +08:00
添加 github.com/pion/dtls 代码
This commit is contained in:
43
dtls-2.0.9/pkg/protocol/extension/renegotiation_info.go
Normal file
43
dtls-2.0.9/pkg/protocol/extension/renegotiation_info.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package extension
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
const (
|
||||
renegotiationInfoHeaderSize = 5
|
||||
)
|
||||
|
||||
// RenegotiationInfo allows a Client/Server to
|
||||
// communicate their renegotation support
|
||||
//
|
||||
// https://tools.ietf.org/html/rfc5746
|
||||
type RenegotiationInfo struct {
|
||||
RenegotiatedConnection uint8
|
||||
}
|
||||
|
||||
// TypeValue returns the extension TypeValue
|
||||
func (r RenegotiationInfo) TypeValue() TypeValue {
|
||||
return RenegotiationInfoTypeValue
|
||||
}
|
||||
|
||||
// Marshal encodes the extension
|
||||
func (r *RenegotiationInfo) Marshal() ([]byte, error) {
|
||||
out := make([]byte, renegotiationInfoHeaderSize)
|
||||
|
||||
binary.BigEndian.PutUint16(out, uint16(r.TypeValue()))
|
||||
binary.BigEndian.PutUint16(out[2:], uint16(1)) // length
|
||||
out[4] = r.RenegotiatedConnection
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Unmarshal populates the extension from encoded data
|
||||
func (r *RenegotiationInfo) Unmarshal(data []byte) error {
|
||||
if len(data) < renegotiationInfoHeaderSize {
|
||||
return errBufferTooSmall
|
||||
} else if TypeValue(binary.BigEndian.Uint16(data)) != r.TypeValue() {
|
||||
return errInvalidExtensionType
|
||||
}
|
||||
|
||||
r.RenegotiatedConnection = data[4]
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user