blob: 9681267d5a04ea076e47d15a984b203560608aae (
plain)
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
|
package sctp
import (
"crypto/rand"
"fmt"
)
type paramStateCookie struct {
paramHeader
cookie []byte
}
func newRandomStateCookie() (*paramStateCookie, error) {
randCookie := make([]byte, 32)
_, err := rand.Read(randCookie)
// crypto/rand.Read returns n == len(b) if and only if err == nil.
if err != nil {
return nil, err
}
s := ¶mStateCookie{
cookie: randCookie,
}
return s, nil
}
func (s *paramStateCookie) marshal() ([]byte, error) {
s.typ = stateCookie
s.raw = s.cookie
return s.paramHeader.marshal()
}
func (s *paramStateCookie) unmarshal(raw []byte) (param, error) {
err := s.paramHeader.unmarshal(raw)
if err != nil {
return nil, err
}
s.cookie = s.raw
return s, nil
}
// String makes paramStateCookie printable
func (s *paramStateCookie) String() string {
return fmt.Sprintf("%s: %s", s.paramHeader, s.cookie)
}
|