forked from pion/srtp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protection_profile.go
78 lines (70 loc) · 2.04 KB
/
protection_profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package srtp
import "fmt"
// ProtectionProfile specifies Cipher and AuthTag details, similar to TLS cipher suite
type ProtectionProfile uint16
// Supported protection profiles
const (
ProtectionProfileAes128CmHmacSha1_80 ProtectionProfile = 0x0001
ProtectionProfileAeadAes128Gcm ProtectionProfile = 0x0007
ProtectionProfileUnencrypted ProtectionProfile = 0x0010
)
func (p ProtectionProfile) keyLen() (int, error) {
switch p {
case ProtectionProfileAes128CmHmacSha1_80:
fallthrough
case ProtectionProfileAeadAes128Gcm:
return 16, nil
case ProtectionProfileUnencrypted:
return 0, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) saltLen() (int, error) {
switch p {
case ProtectionProfileAes128CmHmacSha1_80:
return 14, nil
case ProtectionProfileAeadAes128Gcm:
return 12, nil
case ProtectionProfileUnencrypted:
return 0, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) authTagLen() (int, error) {
switch p {
case ProtectionProfileAes128CmHmacSha1_80:
return (&srtpCipherAesCmHmacSha1{}).authTagLen(), nil
case ProtectionProfileAeadAes128Gcm:
return (&srtpCipherAeadAesGcm{}).authTagLen(), nil
case ProtectionProfileUnencrypted:
return 0, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) aeadAuthTagLen() (int, error) {
switch p {
case ProtectionProfileAes128CmHmacSha1_80:
return (&srtpCipherAesCmHmacSha1{}).aeadAuthTagLen(), nil
case ProtectionProfileAeadAes128Gcm:
return (&srtpCipherAeadAesGcm{}).aeadAuthTagLen(), nil
case ProtectionProfileUnencrypted:
return 0, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}
func (p ProtectionProfile) authKeyLen() (int, error) {
switch p {
case ProtectionProfileAes128CmHmacSha1_80:
return 20, nil
case ProtectionProfileAeadAes128Gcm:
return 0, nil
case ProtectionProfileUnencrypted:
return 0, nil
default:
return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
}
}