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.
12
// LiteralData represents an encrypted file. See RFC 4880, section 5.9.
13
type LiteralData struct {
16
Time uint32 // Unix epoch time. Either creation time or modification time. 0 means undefined.
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"
26
func (l *LiteralData) parse(r io.Reader) (err error) {
29
_, err = readFull(r, buf[:2])
34
l.IsBinary = buf[0] == 'b'
35
fileNameLen := int(buf[1])
37
_, err = readFull(r, buf[:fileNameLen])
42
l.FileName = string(buf[:fileNameLen])
44
_, err = readFull(r, buf[:4])
49
l.Time = binary.BigEndian.Uint32(buf[:4])
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) {
63
if len(fileName) > 255 {
64
fileName = fileName[:255]
66
buf[1] = byte(len(fileName))
68
inner, err := serializeStreamHeader(w, packetTypeLiteralData)
73
_, err = inner.Write(buf[:2])
77
_, err = inner.Write([]byte(fileName))
81
binary.BigEndian.PutUint32(buf[:], time)
82
_, err = inner.Write(buf[:])