mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-09 05:50:59 +08:00
添加 github.com/pion/dtls 代码
This commit is contained in:
29
dtls-2.0.9/pkg/protocol/handshake/cipher_suite.go
Normal file
29
dtls-2.0.9/pkg/protocol/handshake/cipher_suite.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package handshake
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
func decodeCipherSuiteIDs(buf []byte) ([]uint16, error) {
|
||||
if len(buf) < 2 {
|
||||
return nil, errBufferTooSmall
|
||||
}
|
||||
cipherSuitesCount := int(binary.BigEndian.Uint16(buf[0:])) / 2
|
||||
rtrn := make([]uint16, cipherSuitesCount)
|
||||
for i := 0; i < cipherSuitesCount; i++ {
|
||||
if len(buf) < (i*2 + 4) {
|
||||
return nil, errBufferTooSmall
|
||||
}
|
||||
|
||||
rtrn[i] = binary.BigEndian.Uint16(buf[(i*2)+2:])
|
||||
}
|
||||
return rtrn, nil
|
||||
}
|
||||
|
||||
func encodeCipherSuiteIDs(cipherSuiteIDs []uint16) []byte {
|
||||
out := []byte{0x00, 0x00}
|
||||
binary.BigEndian.PutUint16(out[len(out)-2:], uint16(len(cipherSuiteIDs)*2))
|
||||
for _, id := range cipherSuiteIDs {
|
||||
out = append(out, []byte{0x00, 0x00}...)
|
||||
binary.BigEndian.PutUint16(out[len(out)-2:], id)
|
||||
}
|
||||
return out
|
||||
}
|
Reference in New Issue
Block a user