~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/code.google.com/p/go.crypto/openpgp/packet/literal.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        "encoding/binary"
 
9
        "io"
 
10
)
 
11
 
 
12
// LiteralData represents an encrypted file. See RFC 4880, section 5.9.
 
13
type LiteralData struct {
 
14
        IsBinary bool
 
15
        FileName string
 
16
        Time     uint32 // Unix epoch time. Either creation time or modification time. 0 means undefined.
 
17
        Body     io.Reader
 
18
}
 
19
 
 
20
// ForEyesOnly returns whether the contents of the LiteralData have been marked
 
21
// as especially sensitive.
 
22
func (l *LiteralData) ForEyesOnly() bool {
 
23
        return l.FileName == "_CONSOLE"
 
24
}
 
25
 
 
26
func (l *LiteralData) parse(r io.Reader) (err error) {
 
27
        var buf [256]byte
 
28
 
 
29
        _, err = readFull(r, buf[:2])
 
30
        if err != nil {
 
31
                return
 
32
        }
 
33
 
 
34
        l.IsBinary = buf[0] == 'b'
 
35
        fileNameLen := int(buf[1])
 
36
 
 
37
        _, err = readFull(r, buf[:fileNameLen])
 
38
        if err != nil {
 
39
                return
 
40
        }
 
41
 
 
42
        l.FileName = string(buf[:fileNameLen])
 
43
 
 
44
        _, err = readFull(r, buf[:4])
 
45
        if err != nil {
 
46
                return
 
47
        }
 
48
 
 
49
        l.Time = binary.BigEndian.Uint32(buf[:4])
 
50
        l.Body = r
 
51
        return
 
52
}
 
53
 
 
54
// SerializeLiteral serializes a literal data packet to w and returns a
 
55
// WriteCloser to which the data itself can be written and which MUST be closed
 
56
// on completion. The fileName is truncated to 255 bytes.
 
57
func SerializeLiteral(w io.WriteCloser, isBinary bool, fileName string, time uint32) (plaintext io.WriteCloser, err error) {
 
58
        var buf [4]byte
 
59
        buf[0] = 't'
 
60
        if isBinary {
 
61
                buf[0] = 'b'
 
62
        }
 
63
        if len(fileName) > 255 {
 
64
                fileName = fileName[:255]
 
65
        }
 
66
        buf[1] = byte(len(fileName))
 
67
 
 
68
        inner, err := serializeStreamHeader(w, packetTypeLiteralData)
 
69
        if err != nil {
 
70
                return
 
71
        }
 
72
 
 
73
        _, err = inner.Write(buf[:2])
 
74
        if err != nil {
 
75
                return
 
76
        }
 
77
        _, err = inner.Write([]byte(fileName))
 
78
        if err != nil {
 
79
                return
 
80
        }
 
81
        binary.BigEndian.PutUint32(buf[:], time)
 
82
        _, err = inner.Write(buf[:])
 
83
        if err != nil {
 
84
                return
 
85
        }
 
86
 
 
87
        plaintext = inner
 
88
        return
 
89
}