-
Notifications
You must be signed in to change notification settings - Fork 0
Property testing crypto package #49
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
Conversation
Signed-off-by: nabil salah <nabil.salah203@gmail.com>
Signed-off-by: nabil salah <nabil.salah203@gmail.com>
pkg/crypto/crypto_property_test.go
Outdated
|
|
||
| // Helper functions | ||
|
|
||
| func bytesEqual(a, b []byte) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
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 |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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>
Description
Describe the changes introduced by this PR and what does it affect
Changes
List of changes this PR includes
Related Issues
Checklist