From 6c95fc6ac71b68fc19687837919e757d50c107af Mon Sep 17 00:00:00 2001 From: Haris Khan Date: Sun, 15 Sep 2024 21:48:51 -0400 Subject: [PATCH] -Critical change: trim newline from private key -commented out newline investigation in Test_KeyGenerationAndHandling -Test_KeyGnerationAndHandling works as expected now. --- I2PAddr.go | 6 ++++++ I2PAddr_test.go | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/I2PAddr.go b/I2PAddr.go index f175a40..2225588 100644 --- a/I2PAddr.go +++ b/I2PAddr.go @@ -337,6 +337,10 @@ HELLO VERSION MIN=3.1 MAX=3.1 DEST GENERATE SIGNATURE_TYPE=7 */ func NewDestination() (*I2PKeys, error) { + removeNewlines := func(s string) string { + return strings.ReplaceAll(strings.ReplaceAll(s, "\r\n", ""), "\n", "") + } + // conn, err := net.Dial("tcp", "127.0.0.1:7656") if err != nil { return nil, err @@ -369,6 +373,8 @@ func NewDestination() (*I2PKeys, error) { pub := strings.Split(strings.Split(string(buf[:n]), "PRIV=")[0], "PUB=")[1] priv := strings.Split(string(buf[:n]), "PRIV=")[1] + priv = removeNewlines(priv) //There is an extraneous newline in the private key, so we'll remove it. + return &I2PKeys{ Address: I2PAddr(pub), Both: pub + priv, diff --git a/I2PAddr_test.go b/I2PAddr_test.go index fe143c1..d0ecbbd 100644 --- a/I2PAddr_test.go +++ b/I2PAddr_test.go @@ -156,9 +156,12 @@ func Test_I2PAddrToBytes(t *testing.T) { } }) } -func removeNewlines(s string) string { - return strings.ReplaceAll(strings.ReplaceAll(s, "\r\n", ""), "\n", "") -} + +/* + func removeNewlines(s string) string { + return strings.ReplaceAll(strings.ReplaceAll(s, "\r\n", ""), "\n", "") + } +*/ func Test_KeyGenerationAndHandling(t *testing.T) { // Generate new keys keys, err := NewDestination() @@ -190,9 +193,11 @@ func Test_KeyGenerationAndHandling(t *testing.T) { } if loadedKeys.Both != keys.Both { t.Errorf("LoadKeysIncompat returned incorrect pair. Got '%s'\nwant '%s'\n", loadedKeys.Both, keys.Both) - if loadedKeys.Both == removeNewlines(keys.Both) { - fmt.Println("However, both pairs are correct if newline is removed in generated keys.") - } + /* + if loadedKeys.Both == removeNewlines(keys.Both) { + fmt.Println("However, both pairs are correct if newline is removed in generated keys.") + } + */ } })