status-go/vendor/github.com/pion/srtp/v2/protection_profile.go

87 lines
2.6 KiB
Go
Raw Normal View History

2024-05-15 23:15:00 +00:00
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
2022-03-10 09:44:48 +00:00
package srtp
import "fmt"
// ProtectionProfile specifies Cipher and AuthTag details, similar to TLS cipher suite
type ProtectionProfile uint16
// Supported protection profiles
2024-05-15 23:15:00 +00:00
// See https://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
2022-03-10 09:44:48 +00:00
const (
ProtectionProfileAes128CmHmacSha1_80 ProtectionProfile = 0x0001
2024-05-15 23:15:00 +00:00
ProtectionProfileAes128CmHmacSha1_32 ProtectionProfile = 0x0002
2022-03-10 09:44:48 +00:00
ProtectionProfileAeadAes128Gcm ProtectionProfile = 0x0007
2024-05-15 23:15:00 +00:00
ProtectionProfileAeadAes256Gcm ProtectionProfile = 0x0008
2022-03-10 09:44:48 +00:00
)
func (p ProtectionProfile) keyLen() (int, error) {
switch p {
2024-05-15 23:15:00 +00:00
case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80, ProtectionProfileAeadAes128Gcm:
2022-03-10 09:44:48 +00:00
return 16, nil
2024-05-15 23:15:00 +00:00
case ProtectionProfileAeadAes256Gcm:
return 32, nil
2022-03-10 09:44:48 +00:00
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) saltLen() (int, error) {
switch p {
2024-05-15 23:15:00 +00:00
case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
2022-03-10 09:44:48 +00:00
return 14, nil
2024-05-15 23:15:00 +00:00
case ProtectionProfileAeadAes128Gcm, ProtectionProfileAeadAes256Gcm:
2022-03-10 09:44:48 +00:00
return 12, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
2024-05-15 23:15:00 +00:00
func (p ProtectionProfile) rtpAuthTagLen() (int, error) {
2022-03-10 09:44:48 +00:00
switch p {
case ProtectionProfileAes128CmHmacSha1_80:
2024-05-15 23:15:00 +00:00
return 10, nil
case ProtectionProfileAes128CmHmacSha1_32:
return 4, nil
case ProtectionProfileAeadAes128Gcm, ProtectionProfileAeadAes256Gcm:
return 0, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) rtcpAuthTagLen() (int, error) {
switch p {
case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
return 10, nil
case ProtectionProfileAeadAes128Gcm, ProtectionProfileAeadAes256Gcm:
return 0, nil
2022-03-10 09:44:48 +00:00
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) aeadAuthTagLen() (int, error) {
switch p {
2024-05-15 23:15:00 +00:00
case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
return 0, nil
case ProtectionProfileAeadAes128Gcm, ProtectionProfileAeadAes256Gcm:
return 16, nil
2022-03-10 09:44:48 +00:00
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) authKeyLen() (int, error) {
switch p {
2024-05-15 23:15:00 +00:00
case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
2022-03-10 09:44:48 +00:00
return 20, nil
2024-05-15 23:15:00 +00:00
case ProtectionProfileAeadAes128Gcm, ProtectionProfileAeadAes256Gcm:
2022-03-10 09:44:48 +00:00
return 0, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}