Crypt-NaCl-Sodium
view release on metacpan or search on metacpan
t/threads.t view on Meta::CPAN
{
my $crypto_auth = Crypt::NaCl::Sodium->auth;
my $key = $crypto_auth->keygen;
my $hasher = $crypto_auth->hmacsha256_init($key);
$hasher->update("foo");
my $tdigest = threads->create(sub { $hasher->update("bar"); $hasher->final })->join;
isnt $hasher->clone->final->to_hex, $tdigest->to_hex, "unshared object unaffected by the thread";
$hasher->update("bar");
is $hasher->clone->final->to_hex, $tdigest->to_hex, "final mac matches";
}
{
my $crypto_auth = Crypt::NaCl::Sodium->auth;
my $key = $crypto_auth->keygen;
my $hasher = $crypto_auth->hmacsha512_init($key);
$hasher->update("foo");
my $tdigest = threads->create(sub { $hasher->update("bar"); $hasher->final })->join;
isnt $hasher->clone->final->to_hex, $tdigest->to_hex, "unshared object unaffected by the thread";
$hasher->update("bar");
is $hasher->clone->final->to_hex, $tdigest->to_hex, "final mac matches";
}
{
my $crypto_auth = Crypt::NaCl::Sodium->auth;
my $key = $crypto_auth->keygen;
my $hasher = $crypto_auth->hmacsha512256_init($key);
$hasher->update("foo");
my $tdigest = threads->create(sub { $hasher->update("bar"); $hasher->final })->join;
isnt $hasher->clone->final->to_hex, $tdigest->to_hex, "unshared object unaffected by the thread";
$hasher->update("bar");
is $hasher->clone->final->to_hex, $tdigest->to_hex, "final mac matches";
}
{
my $crypto_onetimeauth = Crypt::NaCl::Sodium->onetimeauth;
my $key = $crypto_onetimeauth->keygen;
my $hasher = $crypto_onetimeauth->init($key);
$hasher->update("foo");
my $tdigest = threads->create(sub { $hasher->update("bar"); $hasher->final })->join;
isnt $hasher->clone->final->to_hex, $tdigest->to_hex, "unshared object unaffected by the thread";
$hasher->update("bar");
is $hasher->clone->final->to_hex, $tdigest->to_hex, "final mac matches";
}
SKIP: {
my $crypto_aead = Crypt::NaCl::Sodium->aead;
skip "AES256GCM is not available", 1 unless $crypto_aead->aes256gcm_is_available;
my $key = $crypto_aead->aes256gcm_keygen;
my $precal_key = $crypto_aead->aes256gcm_beforenm($key);
my $tprecal_key = threads->create(sub { $precal_key->lock(); $precal_key->is_locked })->join;
isnt $precal_key->is_locked, $tprecal_key, "unshared object unaffected by the thread";
}
done_testing();
( run in 1.972 second using v1.01-cache-2.11-cpan-d8267643d1d )