Move getters to file excluded from android build (#88)
This commit is contained in:
parent
ac353fcbef
commit
d53bd4a351
6 changed files with 26 additions and 20 deletions
|
|
@ -109,7 +109,7 @@ func (keyRing *KeyRing) EncryptAttachment(message *PlainMessage, filename string
|
||||||
len(message.GetBinary()),
|
len(message.GetBinary()),
|
||||||
filename,
|
filename,
|
||||||
message.IsBinary(),
|
message.IsBinary(),
|
||||||
message.GetTime(),
|
message.Time,
|
||||||
-1,
|
-1,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/openpgp"
|
"golang.org/x/crypto/openpgp"
|
||||||
"golang.org/x/crypto/openpgp/packet"
|
"golang.org/x/crypto/openpgp/packet"
|
||||||
|
|
@ -86,8 +85,8 @@ func asymmetricEncrypt(plainMessage *PlainMessage, publicKey, privateKey *KeyRin
|
||||||
|
|
||||||
hints := &openpgp.FileHints{
|
hints := &openpgp.FileHints{
|
||||||
IsBinary: plainMessage.IsBinary(),
|
IsBinary: plainMessage.IsBinary(),
|
||||||
FileName: plainMessage.GetFilename(),
|
FileName: plainMessage.Filename,
|
||||||
ModTime: time.Unix(int64(plainMessage.GetTime()), 0),
|
ModTime: plainMessage.getFormattedTime(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if plainMessage.IsBinary() {
|
if plainMessage.IsBinary() {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ProtonMail/gopenpgp/v2/armor"
|
"github.com/ProtonMail/gopenpgp/v2/armor"
|
||||||
"github.com/ProtonMail/gopenpgp/v2/constants"
|
"github.com/ProtonMail/gopenpgp/v2/constants"
|
||||||
|
|
@ -220,14 +221,9 @@ func (msg *PlainMessage) IsBinary() bool {
|
||||||
return !msg.TextType
|
return !msg.TextType
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFilename returns the file name of the message as a string.
|
// getFormattedTime returns the message (latest modification) Time as time.Time.
|
||||||
func (msg *PlainMessage) GetFilename() string {
|
func (msg *PlainMessage) getFormattedTime() time.Time {
|
||||||
return msg.Filename
|
return time.Unix(int64(msg.Time), 0)
|
||||||
}
|
|
||||||
|
|
||||||
// GetTime returns the modification time of a file (if provided in the ciphertext).
|
|
||||||
func (msg *PlainMessage) GetTime() uint32 {
|
|
||||||
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.
|
||||||
|
|
|
||||||
13
crypto/message_getters.go
Normal file
13
crypto/message_getters.go
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
// +build !android
|
||||||
|
|
||||||
|
package crypto
|
||||||
|
|
||||||
|
// GetFilename returns the file name of the message as a string.
|
||||||
|
func (msg *PlainMessage) GetFilename() string {
|
||||||
|
return msg.Filename
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTime returns the modification time of a file (if provided in the ciphertext).
|
||||||
|
func (msg *PlainMessage) GetTime() uint32 {
|
||||||
|
return msg.Time
|
||||||
|
}
|
||||||
|
|
@ -3,12 +3,10 @@ package crypto
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/openpgp"
|
|
||||||
"golang.org/x/crypto/openpgp/packet"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/crypto/openpgp"
|
||||||
|
"golang.org/x/crypto/openpgp/packet"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EncryptMessageWithPassword encrypts a PlainMessage to PGPMessage with a
|
// EncryptMessageWithPassword encrypts a PlainMessage to PGPMessage with a
|
||||||
|
|
@ -115,8 +113,8 @@ func passwordEncrypt(message *PlainMessage, password []byte) ([]byte, error) {
|
||||||
|
|
||||||
hints := &openpgp.FileHints{
|
hints := &openpgp.FileHints{
|
||||||
IsBinary: message.IsBinary(),
|
IsBinary: message.IsBinary(),
|
||||||
FileName: message.GetFilename(),
|
FileName: message.Filename,
|
||||||
ModTime: time.Unix(int64(message.GetTime()), 0),
|
ModTime: message.getFormattedTime(),
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptWriter, err := openpgp.SymmetricallyEncrypt(&outBuf, password, hints, config)
|
encryptWriter, err := openpgp.SymmetricallyEncrypt(&outBuf, password, hints, config)
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,8 @@ func (sk *SessionKey) Encrypt(message *PlainMessage) ([]byte, error) {
|
||||||
encryptWriter, err = packet.SerializeLiteral(
|
encryptWriter, err = packet.SerializeLiteral(
|
||||||
encryptWriter,
|
encryptWriter,
|
||||||
message.IsBinary(),
|
message.IsBinary(),
|
||||||
message.GetFilename(),
|
message.Filename,
|
||||||
message.GetTime(),
|
message.Time,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue