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.

29 lines
657 B

  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. }