-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Only allow ED25519 curve for now, but cache it to reduce amount of …
…init calls - add marshaling test
- Loading branch information
Showing
4 changed files
with
70 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package elgamal | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestCiphertext_MarshalJSON(t *testing.T) { | ||
privateKey, _ := generateKey() | ||
eg := NewTwistedElgamal() | ||
|
||
keys, _ := eg.KeyGen(*privateKey, DefaultTestDenom) | ||
|
||
value := uint64(108) | ||
ciphertext, _, err := eg.Encrypt(keys.PublicKey, value) | ||
|
||
// Marshal the Ciphertext to JSON | ||
data, err := json.Marshal(ciphertext) | ||
require.NoError(t, err, "Marshaling should not produce an error") | ||
|
||
// Unmarshal the JSON back to a Ciphertext | ||
var unmarshaled Ciphertext | ||
err = json.Unmarshal(data, &unmarshaled) | ||
require.NoError(t, err, "Unmarshaling should not produce an error") | ||
|
||
// Compare the original and unmarshaled Ciphertext | ||
require.True(t, ciphertext.C.Equal(unmarshaled.C), "C points should be equal") | ||
require.True(t, ciphertext.D.Equal(unmarshaled.D), "D points should be equal") | ||
|
||
} |