Ai
10 Star 41 Fork 20

Gitee 极速下载/Pion-WebRTC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/pion/webrtc
克隆/下载
param_requested_hmac_algorithm.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
Sean DuBois 提交于 2018-07-25 16:00 +08:00 . Switch from individual linters to golangci-lint
package sctp
import (
"encoding/binary"
"fmt"
"github.com/pkg/errors"
)
type hmacAlgorithm uint16
const (
hmacResv1 hmacAlgorithm = 0
hmacSHA128 = 1
hmacResv2 hmacAlgorithm = 2
hmacSHA256 hmacAlgorithm = 3
)
func (c hmacAlgorithm) String() string {
switch c {
case hmacResv1:
return "HMAC Reserved (0x00)"
case hmacSHA128:
return "HMAC SHA-128"
case hmacResv2:
return "HMAC Reserved (0x02)"
case hmacSHA256:
return "HMAC SHA-256"
default:
return fmt.Sprintf("Unknown HMAC Algorithm type: %d", c)
}
}
type paramRequestedHMACAlgorithm struct {
paramHeader
availableAlgorithms []hmacAlgorithm
}
func (r *paramRequestedHMACAlgorithm) marshal() ([]byte, error) {
r.typ = reqHMACAlgo
r.raw = make([]byte, len(r.availableAlgorithms)*2)
i := 0
for _, a := range r.availableAlgorithms {
binary.BigEndian.PutUint16(r.raw[i:], uint16(a))
i += 2
}
return r.paramHeader.marshal()
}
func (r *paramRequestedHMACAlgorithm) unmarshal(raw []byte) (param, error) {
r.paramHeader.unmarshal(raw)
i := 0
for i < len(r.raw) {
a := hmacAlgorithm(binary.BigEndian.Uint16(r.raw[i:]))
switch a {
case hmacSHA128:
fallthrough
case hmacSHA256:
r.availableAlgorithms = append(r.availableAlgorithms, a)
default:
return nil, errors.Errorf("Invalid algorithm type '%v'", a)
}
i += 2
}
return r, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/Pion-WebRTC.git
git@gitee.com:mirrors/Pion-WebRTC.git
mirrors
Pion-WebRTC
Pion-WebRTC
v1.1.1

搜索帮助