summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/asn1-ber.v1/header.go
blob: 123744e9b87722b023434917c768980e94d6d1c6 (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
package ber

import (
	"errors"
	"io"
)

func readHeader(reader io.Reader) (identifier Identifier, length int, read int, err error) {
	if i, c, err := readIdentifier(reader); err != nil {
		return Identifier{}, 0, read, err
	} else {
		identifier = i
		read += c
	}

	if l, c, err := readLength(reader); err != nil {
		return Identifier{}, 0, read, err
	} else {
		length = l
		read += c
	}

	// Validate length type with identifier (x.600, 8.1.3.2.a)
	if length == LengthIndefinite && identifier.TagType == TypePrimitive {
		return Identifier{}, 0, read, errors.New("indefinite length used with primitive type")
	}

	return identifier, length, read, nil
}