forked from gopcua/opcua
/
symmetric_security_header.go
48 lines (39 loc) · 1.16 KB
/
symmetric_security_header.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
// Copyright 2018-2020 opcua authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package uasc
import (
"fmt"
"github.com/barisvelioglu/opcua/ua"
)
// SymmetricSecurityHeader represents a Symmetric Algorithm Security Header in OPC UA Secure Conversation.
type SymmetricSecurityHeader struct {
TokenID uint32
}
// NewSymmetricSecurityHeader creates a new OPC UA Secure Conversation Symmetric Algorithm Security Header.
func NewSymmetricSecurityHeader(token uint32) *SymmetricSecurityHeader {
return &SymmetricSecurityHeader{
TokenID: token,
}
}
func (h *SymmetricSecurityHeader) Decode(b []byte) (int, error) {
buf := ua.NewBuffer(b)
h.TokenID = buf.ReadUint32()
return buf.Pos(), buf.Error()
}
func (h *SymmetricSecurityHeader) Encode() ([]byte, error) {
buf := ua.NewBuffer(nil)
buf.WriteUint32(h.TokenID)
return buf.Bytes(), buf.Error()
}
// String returns Header in string.
func (h *SymmetricSecurityHeader) String() string {
return fmt.Sprintf(
"TokenID: %d",
h.TokenID,
)
}
// Len returns the Header Length in bytes.
func (h *SymmetricSecurityHeader) Len() int {
return 4
}