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.
 
 
 
 
 
 

43 line
1.0 KiB

  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tls
  5. // The record reader handles reading from the connection and reassembling TLS
  6. // record structures. It loops forever doing this and writes the TLS records to
  7. // it's outbound channel. On error, it closes its outbound channel.
  8. import (
  9. "io";
  10. "bufio";
  11. )
  12. // recordReader loops, reading TLS records from source and writing them to the
  13. // given channel. The channel is closed on EOF or on error.
  14. func recordReader(c chan<- *record, source io.Reader) {
  15. defer close(c);
  16. buf := bufio.NewReader(source);
  17. for {
  18. var header [5]byte;
  19. n, _ := buf.Read(header[0:len(header)]);
  20. if n != 5 {
  21. return;
  22. }
  23. recordLength := int(header[3])<<8 | int(header[4]);
  24. if recordLength > maxTLSCiphertext {
  25. return;
  26. }
  27. payload := make([]byte, recordLength);
  28. n, _ = buf.Read(payload);
  29. if n != recordLength {
  30. return;
  31. }
  32. c <- &record{recordType(header[0]), header[1], header[2], payload};
  33. }
  34. }