compressed.go 827 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2011 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 packet
  5. import (
  6. "code.google.com/p/go.crypto/openpgp/errors"
  7. "compress/flate"
  8. "compress/zlib"
  9. "io"
  10. "strconv"
  11. )
  12. // Compressed represents a compressed OpenPGP packet. The decompressed contents
  13. // will contain more OpenPGP packets. See RFC 4880, section 5.6.
  14. type Compressed struct {
  15. Body io.Reader
  16. }
  17. func (c *Compressed) parse(r io.Reader) error {
  18. var buf [1]byte
  19. _, err := readFull(r, buf[:])
  20. if err != nil {
  21. return err
  22. }
  23. switch buf[0] {
  24. case 1:
  25. c.Body = flate.NewReader(r)
  26. case 2:
  27. c.Body, err = zlib.NewReader(r)
  28. default:
  29. err = errors.UnsupportedError("unknown compression algorithm: " + strconv.Itoa(int(buf[0])))
  30. }
  31. return err
  32. }