Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clearsign.Encode/Decode round trip introduces extra newline? #241

Closed
tri-adam opened this issue Nov 8, 2024 · 1 comment · Fixed by #242
Closed

clearsign.Encode/Decode round trip introduces extra newline? #241

tri-adam opened this issue Nov 8, 2024 · 1 comment · Fixed by #242

Comments

@tri-adam
Copy link

tri-adam commented Nov 8, 2024

Hi there! I'm seeing a change in behaviour as of v1.1.0 (and persisting in v1.1.1) where I don't receive the same plaintext from clearsign.Decode that was provided to clearsign.Encode. Specifically, it looks like an extra newline is introduced at the end.

With this sample code:

package main

import (
	"bytes"
	"crypto/rand"
	"crypto/rsa"
	"encoding/hex"
	"fmt"
	"log"
	"time"

	"github.com/ProtonMail/go-crypto/openpgp/clearsign"
	"github.com/ProtonMail/go-crypto/openpgp/packet"
)

func main() {
	input := []byte("hello\n")
	fmt.Print("Input\t", hex.Dump(input))

	pk, err := rsa.GenerateKey(rand.Reader, 4096)
	if err != nil {
		log.Fatal(err)
	}

	var b bytes.Buffer

	plaintext, err := clearsign.Encode(&b, packet.NewRSAPrivateKey(time.Now(), pk), nil)
	if err != nil {
		log.Fatal(err)
	}
	plaintext.Write(input)
	plaintext.Close()

	block, _ := clearsign.Decode(b.Bytes())

	fmt.Print("Output\t", hex.Dump(block.Plaintext))
}

v1.0.0 outputs:

$ go run ./main.go 
Input   00000000  68 65 6c 6c 6f 0a                                 |hello.|
Output  00000000  68 65 6c 6c 6f 0a                                 |hello.|

With v1.1.1, I get:

$ go mod tidy && go run ./main.go 
Input   00000000  68 65 6c 6c 6f 0a                                 |hello.|
Output  00000000  68 65 6c 6c 6f 0a 0a                              |hello..|

Is this expected?

@tri-adam
Copy link
Author

tri-adam commented Nov 8, 2024

Thank you for the speedy fix (and release) @lubux. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant