Skip to content

Property testing crypto package#49

Merged
Nabil-Salah merged 3 commits into
mainfrom
development_crypto_propertytests
Jul 29, 2025
Merged

Property testing crypto package#49
Nabil-Salah merged 3 commits into
mainfrom
development_crypto_propertytests

Conversation

@Nabil-Salah
Copy link
Copy Markdown
Contributor

Description

Describe the changes introduced by this PR and what does it affect

Changes

List of changes this PR includes

Related Issues

Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstring

Signed-off-by: nabil salah <nabil.salah203@gmail.com>
Signed-off-by: nabil salah <nabil.salah203@gmail.com>
Comment thread pkg/crypto/crypto_property_test.go Outdated

// Helper functions

func bytesEqual(a, b []byte) bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread pkg/crypto/crypto_property_test.go Outdated
func TestEncryptionDecryptionRoundtrip(t *testing.T) {
f := func(kp keyPair, msg randomMessage) bool {
message := []byte(msg)
encrypted, err := Encrypt(message, kp.PublicKey)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract that logic into a function e.g encryptThenDecrypt and the only thing would be left is comparing the decrypted with the message

Comment thread pkg/crypto/crypto_property_test.go Outdated
func (keyPair) Generate(rand *rand.Rand, size int) reflect.Value {
pub, priv, err := ed25519.GenerateKey(crypto_rand.Reader)
if err != nil {
panic(err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Comment thread pkg/crypto/crypto_property_test.go Outdated
}

// NaCl sealed box adds 48 bytes overhead (32 bytes ephemeral key + 16 bytes MAC)
expectedSize := len(message) + 48
Copy link
Copy Markdown
Contributor

@xmonader xmonader Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract the 48 into a constant, and use it here

Comment thread pkg/crypto/crypto_property_test.go Outdated

// Generate implements quick.Generator for keyPair
func (keyPair) Generate(rand *rand.Rand, size int) reflect.Value {
pub, priv, err := ed25519.GenerateKey(crypto_rand.Reader)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have a rand already?

…nctions

Signed-off-by: nabil salah <nabil.salah203@gmail.com>
@Nabil-Salah Nabil-Salah requested a review from xmonader July 29, 2025 14:58
@Nabil-Salah Nabil-Salah merged commit 534345d into main Jul 29, 2025
1 check passed
@Nabil-Salah Nabil-Salah deleted the development_crypto_propertytests branch July 29, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants