Add filename and time properties to message (#85)
* Add filename and time properties to message * Message time defaults to current time
This commit is contained in:
parent
7de8833ff6
commit
a4d89bce32
9 changed files with 134 additions and 51 deletions
|
|
@ -60,9 +60,9 @@ func DecryptAttachment(keyPacket []byte, dataPacket []byte, keyRing *crypto.KeyR
|
|||
// Returns a PGPSplitMessage containing a session key packet and symmetrically
|
||||
// encrypted data. Specifically designed for attachments rather than text
|
||||
// messages.
|
||||
func EncryptAttachment(plainData []byte, fileName string, keyRing *crypto.KeyRing) (*crypto.PGPSplitMessage, error) {
|
||||
plainMessage := crypto.NewPlainMessage(plainData)
|
||||
decrypted, err := keyRing.EncryptAttachment(plainMessage, fileName)
|
||||
func EncryptAttachment(plainData []byte, filename string, keyRing *crypto.KeyRing) (*crypto.PGPSplitMessage, error) {
|
||||
plainMessage := crypto.NewPlainMessageFromFile(plainData, filename, uint32(crypto.GetUnixTime()))
|
||||
decrypted, err := keyRing.EncryptAttachment(plainMessage, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,20 +3,22 @@
|
|||
|
||||
package helper
|
||||
|
||||
import "github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
import (
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
)
|
||||
|
||||
// EncryptSignAttachment encrypts an attachment using a detached signature, given a publicKey, a privateKey
|
||||
// and its passphrase, the filename, and the unencrypted file data.
|
||||
// Returns keypacket, dataPacket and unarmored (!) signature separate.
|
||||
func EncryptSignAttachment(
|
||||
publicKey, privateKey string, passphrase []byte, fileName string, plainData []byte,
|
||||
publicKey, privateKey string, passphrase []byte, filename string, plainData []byte,
|
||||
) (keyPacket, dataPacket, signature []byte, err error) {
|
||||
var publicKeyObj, privateKeyObj, unlockedKeyObj *crypto.Key
|
||||
var publicKeyRing, privateKeyRing *crypto.KeyRing
|
||||
var packets *crypto.PGPSplitMessage
|
||||
var signatureObj *crypto.PGPSignature
|
||||
|
||||
var binMessage = crypto.NewPlainMessage(plainData)
|
||||
var binMessage = crypto.NewPlainMessageFromFile(plainData, filename, uint32(crypto.GetUnixTime()))
|
||||
|
||||
if publicKeyObj, err = crypto.NewKeyFromArmored(publicKey); err != nil {
|
||||
return nil, nil, nil, err
|
||||
|
|
@ -45,7 +47,7 @@ func EncryptSignAttachment(
|
|||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
if packets, err = publicKeyRing.EncryptAttachment(binMessage, fileName); err != nil {
|
||||
if packets, err = publicKeyRing.EncryptAttachment(binMessage, ""); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue