Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-25 11:16:11 +01:00
forgejo/vendor/github.com/go-asn1-ber/asn1-ber/header.go

39 lines
793 B
Go
Raw Normal View History

2016-11-03 23:16:01 +01:00
package ber
import (
"errors"
"fmt"
2016-11-03 23:16:01 +01:00
"io"
)
func readHeader(reader io.Reader) (identifier Identifier, length int, read int, err error) {
var (
c, l int
i Identifier
)
if i, c, err = readIdentifier(reader); err != nil {
2016-11-03 23:16:01 +01:00
return Identifier{}, 0, read, err
}
identifier = i
read += c
2016-11-03 23:16:01 +01:00
if l, c, err = readLength(reader); err != nil {
2016-11-03 23:16:01 +01:00
return Identifier{}, 0, read, err
}
length = l
read += c
2016-11-03 23:16:01 +01:00
// 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")
}
if length < LengthIndefinite {
err = fmt.Errorf("length cannot be less than %d", LengthIndefinite)
return
}
2016-11-03 23:16:01 +01:00
return identifier, length, read, nil
}