header.go 657 B

1234567891011121314151617181920212223242526272829
  1. package ber
  2. import (
  3. "errors"
  4. "io"
  5. )
  6. func readHeader(reader io.Reader) (identifier Identifier, length int, read int, err error) {
  7. if i, c, err := readIdentifier(reader); err != nil {
  8. return Identifier{}, 0, read, err
  9. } else {
  10. identifier = i
  11. read += c
  12. }
  13. if l, c, err := readLength(reader); err != nil {
  14. return Identifier{}, 0, read, err
  15. } else {
  16. length = l
  17. read += c
  18. }
  19. // Validate length type with identifier (x.600, 8.1.3.2.a)
  20. if length == LengthIndefinite && identifier.TagType == TypePrimitive {
  21. return Identifier{}, 0, read, errors.New("indefinite length used with primitive type")
  22. }
  23. return identifier, length, read, nil
  24. }