File: padding.go

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

import (
	"io"
)

// Padding type represents a Padding Packet (Tag 21).
// The padding type is represented by the length of its padding.
// see https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-crypto-refresh#name-padding-packet-tag-21
type Padding int

// parse just ignores the padding content.
func (pad Padding) parse(reader io.Reader) error {
	_, err := io.CopyN(io.Discard, reader, int64(pad))
	return err
}

// SerializePadding writes the padding to writer.
func (pad Padding) SerializePadding(writer io.Writer, rand io.Reader) error {
	err := serializeHeader(writer, packetPadding, int(pad))
	if err != nil {
		return err
	}
	_, err = io.CopyN(writer, rand, int64(pad))
	return err
}