mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
793 B
39 lines
793 B
8 years ago
|
package ber
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
4 years ago
|
"fmt"
|
||
8 years ago
|
"io"
|
||
|
)
|
||
|
|
||
|
func readHeader(reader io.Reader) (identifier Identifier, length int, read int, err error) {
|
||
4 years ago
|
var (
|
||
|
c, l int
|
||
|
i Identifier
|
||
|
)
|
||
|
|
||
|
if i, c, err = readIdentifier(reader); err != nil {
|
||
8 years ago
|
return Identifier{}, 0, read, err
|
||
|
}
|
||
4 years ago
|
identifier = i
|
||
|
read += c
|
||
8 years ago
|
|
||
4 years ago
|
if l, c, err = readLength(reader); err != nil {
|
||
8 years ago
|
return Identifier{}, 0, read, err
|
||
|
}
|
||
4 years ago
|
length = l
|
||
|
read += c
|
||
8 years ago
|
|
||
|
// 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")
|
||
|
}
|
||
|
|
||
4 years ago
|
if length < LengthIndefinite {
|
||
|
err = fmt.Errorf("length cannot be less than %d", LengthIndefinite)
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
return identifier, length, read, nil
|
||
|
}
|