Skip to content

Commit 982b89f

Browse files
committed
Add documentation to the new functions added. Fix some tests.
Fix some poorly worded older documentation statements.
1 parent e4869b7 commit 982b89f

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

Changes

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Change history for Sodium-FFI
22

33
{{$NEXT}}
4+
- Added crypto_box_seal (Thanks, Brian D Foy)
5+
- Added crypto_box_seal_open (Thanks, Brian D Foy)
6+
- Fixed some documentation
47

58
0.008 2023-01-10
69
- Update tagline to say what Sodium is.

META.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"provides" : {
8585
"Sodium::FFI" : {
8686
"file" : "lib/Sodium/FFI.pm",
87-
"version" : "0.008"
87+
"version" : "0.009"
8888
}
8989
},
9090
"release_status" : "stable",
@@ -99,8 +99,9 @@
9999
"web" : "https://github.com/genio/sodium-ffi"
100100
}
101101
},
102-
"version" : "0.008",
102+
"version" : "0.009",
103103
"x_contributors" : [
104+
"brian d foy <[email protected]>",
104105
"Chase Whitener <[email protected]>"
105106
],
106107
"x_generated_by_perl" : "v5.32.1",

README.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ C library. Sodium is a modern, easy-to-use software library for encryption, decr
2323
signatures, password hashing, and more. These bindings have been created using FFI
2424
via [FFI::Platypus](https://metacpan.org/pod/FFI%3A%3APlatypus).
2525

26-
While we also intend to eventually fix [Crypt::NaCl::Sodium](https://metacpan.org/pod/Crypt%3A%3ANaCl%3A%3ASodium) so that it can use newer versions
26+
We also intend to eventually fix [Crypt::NaCl::Sodium](https://metacpan.org/pod/Crypt%3A%3ANaCl%3A%3ASodium) so that it can use newer versions
2727
of LibSodium.
2828

2929
# Crypto Auth Functions
@@ -373,6 +373,37 @@ if ($decrypted eq $msg) {
373373
The [crypto\_box\_open\_easy](https://doc.libsodium.org/public-key_cryptography/authenticated_encryption#combined-mode)
374374
function decrypts a cipher text produced by [crypto\_box\_easy](https://metacpan.org/pod/crypto_box_easy).
375375

376+
## crypto\_box\_seal
377+
378+
```perl
379+
use Sodium::FFI qw(crypto_box_keypair crypto_box_seal);
380+
my ($public_key, $secret_key) = crypto_box_keypair();
381+
my $msg = "test";
382+
my $cipher_text = crypto_box_seal($msg, $public_key);
383+
```
384+
385+
The [crypto\_box\_seal](https://doc.libsodium.org/public-key_cryptography/sealed_boxes)
386+
function encrypts a message for a recipient whose public key is provided. The
387+
function creates a new key pair for each message and attaches the public key
388+
to the ciphertext. The secret key is overwritten and is not accessible after
389+
this function returns.
390+
391+
## crypto\_box\_seal\_open
392+
393+
```perl
394+
use Sodium::FFI qw(crypto_box_keypair crypto_box_seal crypto_box_seal_open);
395+
my ($public_key, $secret_key) = crypto_box_keypair();
396+
my $msg = "test";
397+
my $cipher_text = crypto_box_seal($msg, $public_key);
398+
my $decrypted = crypto_box_seal_open($cipher_text, $public_key, $secret_key);
399+
if ($decrypted eq $msg) {
400+
say "Yay!";
401+
}
402+
```
403+
404+
The [crypto\_box\_seal\_open](https://doc.libsodium.org/public-key_cryptography/sealed_boxes)
405+
function decrypts a cipher text produced by [crypto\_box\_seal](https://metacpan.org/pod/crypto_box_seal).
406+
376407
## crypto\_box\_seed\_keypair
377408

378409
```perl

lib/Sodium/FFI.pm

+28-1
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ C library. Sodium is a modern, easy-to-use software library for encryption, decr
11121112
signatures, password hashing, and more. These bindings have been created using FFI
11131113
via L<FFI::Platypus>.
11141114
1115-
While we also intend to eventually fix L<Crypt::NaCl::Sodium> so that it can use newer versions
1115+
We also intend to eventually fix L<Crypt::NaCl::Sodium> so that it can use newer versions
11161116
of LibSodium.
11171117
11181118
=head1 Crypto Auth Functions
@@ -1430,6 +1430,33 @@ function randomly generates a secret key and a corresponding public key.
14301430
The L<crypto_box_open_easy|https://doc.libsodium.org/public-key_cryptography/authenticated_encryption#combined-mode>
14311431
function decrypts a cipher text produced by L<crypto_box_easy>.
14321432
1433+
=head2 crypto_box_seal
1434+
1435+
use Sodium::FFI qw(crypto_box_keypair crypto_box_seal);
1436+
my ($public_key, $secret_key) = crypto_box_keypair();
1437+
my $msg = "test";
1438+
my $cipher_text = crypto_box_seal($msg, $public_key);
1439+
1440+
The L<crypto_box_seal|https://doc.libsodium.org/public-key_cryptography/sealed_boxes>
1441+
function encrypts a message for a recipient whose public key is provided. The
1442+
function creates a new key pair for each message and attaches the public key
1443+
to the ciphertext. The secret key is overwritten and is not accessible after
1444+
this function returns.
1445+
1446+
=head2 crypto_box_seal_open
1447+
1448+
use Sodium::FFI qw(crypto_box_keypair crypto_box_seal crypto_box_seal_open);
1449+
my ($public_key, $secret_key) = crypto_box_keypair();
1450+
my $msg = "test";
1451+
my $cipher_text = crypto_box_seal($msg, $public_key);
1452+
my $decrypted = crypto_box_seal_open($cipher_text, $public_key, $secret_key);
1453+
if ($decrypted eq $msg) {
1454+
say "Yay!";
1455+
}
1456+
1457+
The L<crypto_box_seal_open|https://doc.libsodium.org/public-key_cryptography/sealed_boxes>
1458+
function decrypts a cipher text produced by L<crypto_box_seal>.
1459+
14331460
=head2 crypto_box_seed_keypair
14341461
14351462
use Sodium::FFI qw(crypto_box_seed_keypair crypto_sign_SEEDBYTES randombytes_buf);

t/pub_key_crypto/box.t

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ subtest crypto_box_seal => sub {
7777
is(length($priv), crypto_box_SECRETKEYBYTES, 'crypto_box_keypair: priv is right length');
7878

7979
my $msg = "Making the hard things possible";
80-
my $nonce = randombytes_buf(crypto_box_NONCEBYTES);
8180

8281
# crypto_box_seal
8382
my $cipher = crypto_box_seal($msg, $pub);

0 commit comments

Comments
 (0)