File: notation.go

package info (click to toggle)
golang-github-protonmail-go-crypto 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: makefile: 10
file content (29 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (4)
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
package packet

// Notation type represents a Notation Data subpacket
// see https://tools.ietf.org/html/rfc4880#section-5.2.3.16
type Notation struct {
	Name            string
	Value           []byte
	IsCritical      bool
	IsHumanReadable bool
}

func (notation *Notation) getData() []byte {
	nameData := []byte(notation.Name)
	nameLen := len(nameData)
	valueLen := len(notation.Value)

	data := make([]byte, 8+nameLen+valueLen)
	if notation.IsHumanReadable {
		data[0] = 0x80
	}

	data[4] = byte(nameLen >> 8)
	data[5] = byte(nameLen)
	data[6] = byte(valueLen >> 8)
	data[7] = byte(valueLen)
	copy(data[8:8+nameLen], nameData)
	copy(data[8+nameLen:], notation.Value)
	return data
}