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