-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Milestone
Description
What version of Go are you using (go version)?
1.16.5
Does this issue reproduce with the latest release?
Not sure
What operating system and processor architecture are you using (go env)?
go env Output
GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/mustafa/.cache/go-build" GOENV="/home/mustafa/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/mustafa/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/mustafa/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16.5" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3209265659=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I want to encrypt and sign messages using Encrypt method with compression enabled
encryptedTextBuffer := new(bytes.Buffer)
encryptor, err := openpgp.Encrypt(encryptedTextBuffer, publicKeyRing, privateKeyRing[0], nil, &packet.Config{
DefaultCipher: packet.CipherAES256,
DefaultHash: crypto.SHA256,
DefaultCompressionAlgo: packet.CompressionZIP,
CompressionConfig: &packet.CompressionConfig{Level: 9},
})
if err != nil {
return "", err
}
But the PGP message is not compressed, I found that Encrypt method don't have compression in place
func Encrypt(ciphertext io.Writer, to []*Entity, signed *Entity, hints *FileHints, config *packet.Config) (plaintext io.WriteCloser, err error) {
...
payload, err := packet.SerializeSymmetricallyEncrypted(ciphertext, cipher, symKey, config)
if err != nil {
return
}
literaldata := payload
if algo := config.Compression(); algo != packet.CompressionNone {
var compConfig *packet.CompressionConfig
if config != nil {
compConfig = config.CompressionConfig
}
literaldata, err = packet.SerializeCompressed(payload, algo, compConfig)
if err != nil {
return
}
}
return writeAndSign(literaldata, candidateHashes, signed, hints, config)
}
I think need to add compression before calling writeAndSign method, can I make a pull request to fix this problem?
What did you expect to see?
Compressed encrypted and signed PGP message
What did you see instead?
Encrypted and signed but not compressed PGP message