forked from gentlemanautomaton/smb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
capabilities.go
51 lines (43 loc) · 1.49 KB
/
capabilities.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
package smbintegrity
import (
"github.com/gentlemanautomaton/smb/smbtype"
)
// Capabilities interprets a slice of bytes as a set of preauthentication
// integrity capabilities during SMB 3.1.1 protocol negotiation.
//
// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/5a07bd66-4734-4af8-abcf-5a44ff7ee0e5
type Capabilities []byte
// AlgorithmCount returns the number of supported preauthentication hash
// algorithms.
func (c Capabilities) AlgorithmCount() uint16 {
return smbtype.Uint16(c[0:2])
}
// SetAlgorithmCount sets the number of supported preauthentication hash
// algorithms.
func (c Capabilities) SetAlgorithmCount(count uint16) {
smbtype.PutUint16(c[0:2], count)
}
// SaltLength returns the length of the salt used for preauthentication
// integrity.
func (c Capabilities) SaltLength() uint16 {
return smbtype.Uint16(c[2:4])
}
// SetSaltLength sets the length of the salt used for preauthentication
// integrity.
func (c Capabilities) SetSaltLength(length uint16) {
smbtype.PutUint16(c[2:4], length)
}
// Algorithms returns the list of supported preauthentication hash algorithms.
func (c Capabilities) Algorithms() List {
start := uint(4)
length := uint(c.AlgorithmCount()) * 2
end := start + length
return List(c[start:end:end])
}
// Salt returns the salt used for preauthentication integrity.
func (c Capabilities) Salt() []byte {
start := uint(4) + uint(c.AlgorithmCount())*2
length := uint(c.SaltLength())
end := start + length
return []byte(c[start:end:end])
}