mirror of https://github.com/gogits/gogs.git
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.
30 lines
657 B
30 lines
657 B
8 years ago
|
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
|
||
|
}
|