Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
go-version: "${{ steps.gover.outputs.goversion }}"
- run: |
go mod download
go test -race -coverprofile=coverage.txt -covermode=atomic
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
36 changes: 25 additions & 11 deletions crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,38 @@ func TestRoundtrip(t *testing.T) {
})
}

func ExampleEncrypt(peerPublic [32]byte) {
var kp Keypair
if err := kp.Generate(); err != nil {
func ExampleEncrypter_Encrypt() {
var ephemeral, recipient Keypair
if err := ephemeral.Generate(); err != nil {
panic(err)
}
if err := recipient.Generate(); err != nil {
panic(err)
}

encrypter := kp.Encrypter(peerPublic)
encrypter := ephemeral.Encrypter(recipient.Public)
boxed, err := encrypter.Encrypt([]byte("this is my message"))
fmt.Println(boxed, err)
fmt.Println(err == nil, len(boxed) > 0)
// Output: true true
}

func ExampleDecrypt(myPublic, myPrivate [32]byte, encrypted []byte) {
kp := Keypair{
Public: myPublic,
Private: myPrivate,
func ExampleDecrypter_Decrypt() {
var ephemeral, recipient Keypair
if err := ephemeral.Generate(); err != nil {
panic(err)
}
if err := recipient.Generate(); err != nil {
panic(err)
}

encrypter := ephemeral.Encrypter(recipient.Public)
encrypted, err := encrypter.Encrypt([]byte("this is my message"))
if err != nil {
panic(err)
}

decrypter := kp.Decrypter()
decrypter := recipient.Decrypter()
plaintext, err := decrypter.Decrypt(encrypted)
fmt.Println(plaintext, err)
fmt.Println(string(plaintext), err)
// Output: this is my message <nil>
}
Loading