diff --git a/crypto/key.go b/crypto/key.go index c8450838..bf886af9 100644 --- a/crypto/key.go +++ b/crypto/key.go @@ -54,10 +54,16 @@ func NewKeyFromReaderExplicit(r io.Reader, encoding int8) (key *Key, err error) } // NewKey creates a new key from the first key in the unarmored or armored binary data. +// Clones the binKeys data for go-mobile compatibility. func NewKey(binKeys []byte) (key *Key, err error) { return NewKeyFromReader(bytes.NewReader(clone(binKeys))) } +// CreateKeyNoClone creates a new key from the first key in the unarmored or armored binary data. +func CreateKeyNoClone(binKeys []byte) (key *Key, err error) { + return NewKeyFromReader(bytes.NewReader(binKeys)) +} + // NewKeyFromArmored creates a new key from the first key in an armored string. func NewKeyFromArmored(armored string) (key *Key, err error) { return NewKeyFromReader(strings.NewReader(armored)) diff --git a/crypto/message.go b/crypto/message.go index dc29f5a0..f781a759 100644 --- a/crypto/message.go +++ b/crypto/message.go @@ -56,15 +56,21 @@ func NewMetadata(isUTF8 bool) *LiteralMetadata { } // NewPGPMessage generates a new PGPMessage from the unarmored binary data. +// Clones the data for go-mobile compatibility. func NewPGPMessage(data []byte) *PGPMessage { + return NewPGPMessageNoClone(clone(data)) +} + +// NewPGPMessageNoClone generates a new PGPMessage from the unarmored binary data. +func NewPGPMessageNoClone(data []byte) *PGPMessage { pgpMessage := &PGPMessage{ - DataPacket: clone(data), + DataPacket: data, } pgpMessage, err := pgpMessage.splitMessage() if err != nil { // If there is an error in split treat the data as data packets. return &PGPMessage{ - DataPacket: clone(data), + DataPacket: data, } } return pgpMessage @@ -92,6 +98,7 @@ func NewPGPMessageFromArmored(armored string) (*PGPMessage, error) { } // NewPGPSplitMessage generates a new PGPSplitMessage from the binary unarmored keypacket and datapacket. +// Clones the slices for go-mobile compatibility. func NewPGPSplitMessage(keyPacket []byte, dataPacket []byte) *PGPMessage { return &PGPMessage{ KeyPacket: clone(keyPacket), @@ -99,6 +106,14 @@ func NewPGPSplitMessage(keyPacket []byte, dataPacket []byte) *PGPMessage { } } +// NewPGPSplitMessageNoClone generates a new PGPSplitMessage from the binary unarmored keypacket and datapacket. +func NewPGPSplitMessageNoClone(keyPacket []byte, dataPacket []byte) *PGPMessage { + return &PGPMessage{ + KeyPacket: keyPacket, + DataPacket: dataPacket, + } +} + // NewPGPMessageBuffer creates a message buffer. func NewPGPMessageBuffer() *PGPMessageBuffer { return &PGPMessageBuffer{ diff --git a/crypto/sessionkey.go b/crypto/sessionkey.go index 90db18d9..e287a119 100644 --- a/crypto/sessionkey.go +++ b/crypto/sessionkey.go @@ -127,6 +127,8 @@ func generateSessionKey(config *packet.Config) (*SessionKey, error) { return GenerateSessionKeyAlgo(cf) } +// NewSessionKeyFromToken creates a SessionKey struct with the given token and algorithm. +// Clones the token for compatibility with go-mobile. func NewSessionKeyFromToken(token []byte, algo string) *SessionKey { return &SessionKey{ Key: clone(token), @@ -134,6 +136,14 @@ func NewSessionKeyFromToken(token []byte, algo string) *SessionKey { } } +// NewSessionKeyFromTokenNoClone creates a SessionKey struct with the given token and algorithm. +func NewSessionKeyFromTokenNoClone(token []byte, algo string) *SessionKey { + return &SessionKey{ + Key: token, + Algo: algo, + } +} + func newSessionKeyFromEncrypted(ek *packet.EncryptedKey) (*SessionKey, error) { var algo string for k, v := range symKeyAlgos {