Make Time and Filename public (#87)

This commit is contained in:
wussler 2020-10-13 13:14:09 +02:00 committed by GitHub
parent ce607e0fa8
commit ac353fcbef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 19 deletions

View file

@ -95,7 +95,7 @@ NewPlainMessageFromFile(data []byte, filename string, modTime int) *PlainMessage
- Use aes256 cipher for password-encrypted messages. - Use aes256 cipher for password-encrypted messages.
- The helpers `EncryptSignMessageArmored`, `DecryptVerifyMessageArmored`, `DecryptVerifyAttachment`, and`DecryptBinaryMessageArmored` - The helpers `EncryptSignMessageArmored`, `DecryptVerifyMessageArmored`, `DecryptVerifyAttachment`, and`DecryptBinaryMessageArmored`
now accept private keys as public keys and perform automatic casting if the keys are locked. now accept private keys as public keys and perform automatic casting if the keys are locked.
- The `PlainMessage` struct now contains the fields `filename` (string) and `time` (uint32) - The `PlainMessage` struct now contains the fields `Filename` (string) and `Time` (uint32)
- All the Decrypt* functions return the filename, type, and time specified in the encrypted message - All the Decrypt* functions return the filename, type, and time specified in the encrypted message
### Fixed ### Fixed

View file

@ -102,7 +102,7 @@ func (keyRing *KeyRing) newAttachmentProcessor(
// Specifically designed for attachments rather than text messages. // Specifically designed for attachments rather than text messages.
func (keyRing *KeyRing) EncryptAttachment(message *PlainMessage, filename string) (*PGPSplitMessage, error) { func (keyRing *KeyRing) EncryptAttachment(message *PlainMessage, filename string) (*PGPSplitMessage, error) {
if filename == "" { if filename == "" {
filename = message.filename filename = message.Filename
} }
ap, err := keyRing.newAttachmentProcessor( ap, err := keyRing.newAttachmentProcessor(
@ -124,7 +124,7 @@ func (keyRing *KeyRing) EncryptAttachment(message *PlainMessage, filename string
} }
// NewLowMemoryAttachmentProcessor creates an AttachmentProcessor which can be used // NewLowMemoryAttachmentProcessor creates an AttachmentProcessor which can be used
// to encrypt a file. It takes an estimatedSize and fileName as hints about the // to encrypt a file. It takes an estimatedSize and filename as hints about the
// file. It is optimized for low-memory environments and collects garbage every // file. It is optimized for low-memory environments and collects garbage every
// megabyte. // megabyte.
func (keyRing *KeyRing) NewLowMemoryAttachmentProcessor( func (keyRing *KeyRing) NewLowMemoryAttachmentProcessor(
@ -160,7 +160,7 @@ func (keyRing *KeyRing) DecryptAttachment(message *PGPSplitMessage) (*PlainMessa
return &PlainMessage{ return &PlainMessage{
Data: b, Data: b,
TextType: !md.LiteralData.IsBinary, TextType: !md.LiteralData.IsBinary,
filename: md.LiteralData.FileName, Filename: md.LiteralData.FileName,
time: md.LiteralData.Time, Time: md.LiteralData.Time,
}, nil }, nil
} }

View file

@ -147,7 +147,7 @@ func asymmetricDecrypt(
return &PlainMessage{ return &PlainMessage{
Data: body, Data: body,
TextType: !messageDetails.LiteralData.IsBinary, TextType: !messageDetails.LiteralData.IsBinary,
filename: messageDetails.LiteralData.FileName, Filename: messageDetails.LiteralData.FileName,
time: messageDetails.LiteralData.Time, Time: messageDetails.LiteralData.Time,
}, err }, err
} }

View file

@ -28,9 +28,9 @@ type PlainMessage struct {
// If the content is text or binary // If the content is text or binary
TextType bool TextType bool
// The file's latest modification time // The file's latest modification time
time uint32 Time uint32
// The encrypted message's filename // The encrypted message's filename
filename string Filename string
} }
// PGPMessage stores a PGP-encrypted message. // PGPMessage stores a PGP-encrypted message.
@ -67,7 +67,7 @@ func NewPlainMessage(data []byte) *PlainMessage {
return &PlainMessage{ return &PlainMessage{
Data: clone(data), Data: clone(data),
TextType: false, TextType: false,
time: uint32(GetUnixTime()), Time: uint32(GetUnixTime()),
} }
} }
@ -78,8 +78,8 @@ func NewPlainMessageFromFile(data []byte, filename string, time uint32) *PlainMe
return &PlainMessage{ return &PlainMessage{
Data: clone(data), Data: clone(data),
TextType: false, TextType: false,
filename: filename, Filename: filename,
time: time, Time: time,
} }
} }
@ -89,7 +89,7 @@ func NewPlainMessageFromString(text string) *PlainMessage {
return &PlainMessage{ return &PlainMessage{
Data: []byte(strings.ReplaceAll(strings.ReplaceAll(text, "\r\n", "\n"), "\n", "\r\n")), Data: []byte(strings.ReplaceAll(strings.ReplaceAll(text, "\r\n", "\n"), "\n", "\r\n")),
TextType: true, TextType: true,
time: uint32(GetUnixTime()), Time: uint32(GetUnixTime()),
} }
} }
@ -222,12 +222,12 @@ func (msg *PlainMessage) IsBinary() bool {
// GetFilename returns the file name of the message as a string. // GetFilename returns the file name of the message as a string.
func (msg *PlainMessage) GetFilename() string { func (msg *PlainMessage) GetFilename() string {
return msg.filename return msg.Filename
} }
// GetTime returns the modification time of a file (if provided in the ciphertext). // GetTime returns the modification time of a file (if provided in the ciphertext).
func (msg *PlainMessage) GetTime() uint32 { func (msg *PlainMessage) GetTime() uint32 {
return msg.time return msg.Time
} }
// GetBinary returns the unarmored binary content of the message as a []byte. // GetBinary returns the unarmored binary content of the message as a []byte.

View file

@ -165,7 +165,7 @@ func passwordDecrypt(encryptedIO io.Reader, password []byte) (*PlainMessage, err
return &PlainMessage{ return &PlainMessage{
Data: messageBuf.Bytes(), Data: messageBuf.Bytes(),
TextType: !md.LiteralData.IsBinary, TextType: !md.LiteralData.IsBinary,
filename: md.LiteralData.FileName, Filename: md.LiteralData.FileName,
time: md.LiteralData.Time, Time: md.LiteralData.Time,
}, nil }, nil
} }

View file

@ -219,8 +219,8 @@ func (sk *SessionKey) Decrypt(dataPacket []byte) (*PlainMessage, error) {
return &PlainMessage{ return &PlainMessage{
Data: messageBuf.Bytes(), Data: messageBuf.Bytes(),
TextType: !md.LiteralData.IsBinary, TextType: !md.LiteralData.IsBinary,
filename: md.LiteralData.FileName, Filename: md.LiteralData.FileName,
time: md.LiteralData.Time, Time: md.LiteralData.Time,
}, err }, err
} }