aboutsummaryrefslogtreecommitdiff
path: root/lib/Net/Hawk/Crypto.pm
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2015-01-17 16:30:02 +0000
committerdakkar <dakkar@thenautilus.net>2015-01-17 16:30:02 +0000
commit9e8b9ce470c26d0578cf65db3cd3da7bab74b6d7 (patch)
tree3051e09d349f784dd8b3cb90ac0fd7c3af5ad20a /lib/Net/Hawk/Crypto.pm
parentadd subtest names (diff)
downloadnet-hawk-9e8b9ce470c26d0578cf65db3cd3da7bab74b6d7.tar.gz
net-hawk-9e8b9ce470c26d0578cf65db3cd3da7bab74b6d7.tar.bz2
net-hawk-9e8b9ce470c26d0578cf65db3cd3da7bab74b6d7.zip
Uri seems to pass a few testsHEADmaster
also it now has a proper implementation
Diffstat (limited to 'lib/Net/Hawk/Crypto.pm')
-rw-r--r--lib/Net/Hawk/Crypto.pm19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/Net/Hawk/Crypto.pm b/lib/Net/Hawk/Crypto.pm
index f69c78e..6f820dd 100644
--- a/lib/Net/Hawk/Crypto.pm
+++ b/lib/Net/Hawk/Crypto.pm
@@ -50,6 +50,13 @@ package Net::Hawk::Crypto {
return $normalized;
};
+ sub is_valid_hash_algorithm(Str $algorithm) is export {
+ return False unless $algorithm;
+ return True if $algorithm eq 'sha1';
+ return True if $algorithm eq 'sha256';
+ return False;
+ }
+
sub digest_for(Str:D $algorithm) {
if ($algorithm eq 'sha1') { return &sha1 }
elsif ($algorithm eq 'sha256') { return &sha256 }
@@ -86,7 +93,6 @@ package Net::Hawk::Crypto {
Hash:D $options
) returns Str is export {
my $normalized = generate_normalized_string(:$type,|$options);
- CATCH { warn $type;warn $options.perl;die $_ }
return calc_hmac(
$normalized,
@@ -110,5 +116,14 @@ package Net::Hawk::Crypto {
$algorithm,
$key,
);
- }
+ };
+
+ sub timestamp_message(
+ %credentials,
+ Int $localtime_offset_msec
+ ) is export {
+ my $ts = now_msecs($localtime_offset_msec);
+ my $tsm = calculate_ts_mac($ts,%credentials);
+ return { :$ts, :$tsm };
+ };
}