diff options
author | dakkar <dakkar@thenautilus.net> | 2014-12-28 16:28:17 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2014-12-28 16:28:17 +0000 |
commit | 3e701d257e51fae43b4e56ef116e96f3a71cc2fb (patch) | |
tree | fe35e5d8c9562e0573a0d8a9518606ccfd755fa8 /lib/Net/Hawk/Crypto.pm | |
parent | crypto partially ported to p6 (diff) | |
download | net-hawk-3e701d257e51fae43b4e56ef116e96f3a71cc2fb.tar.gz net-hawk-3e701d257e51fae43b4e56ef116e96f3a71cc2fb.tar.bz2 net-hawk-3e701d257e51fae43b4e56ef116e96f3a71cc2fb.zip |
all 'header' tests passing
Diffstat (limited to 'lib/Net/Hawk/Crypto.pm')
-rw-r--r-- | lib/Net/Hawk/Crypto.pm | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/lib/Net/Hawk/Crypto.pm b/lib/Net/Hawk/Crypto.pm index e73cc82..1cd5a8d 100644 --- a/lib/Net/Hawk/Crypto.pm +++ b/lib/Net/Hawk/Crypto.pm @@ -68,31 +68,34 @@ package Net::Hawk::Crypto { parse_content_type($content_type), $payload))); }; -} -=begin finish + sub calc_hmac( + Str:D $data, + Str:D $algorithm, + Str:D $key, + ) returns Str { + my $hash_function = digest_for($algorithm); + return MIME::Base64.encode( + hmac($key,$data,$hash_function) + ); + } -sub calculate_mac { - state $argcheck = compile( - Object,Str, - Dict[ - algorithm => Algorithm, - key => Str, - slurpy Any, - ], - HashRef, - ); - my ($self,$type,$credentials,$options) = $argcheck->(@_); + sub calculate_mac( + Str:D $type, + Hash:D $credentials ( Str :$algorithm, Str :$key, *% ), + Hash:D $options + ) returns Str is export { + my $normalized = generate_normalized_string(:$type,|$options); - my $normalized = $self->generate_normalized_string($type,$options); + return calc_hmac( + $normalized, + $algorithm, + $key, + ); + } - return $self->calc_hmac( - $normalized, - $credentials->{algorithm}, - $credentials->{key}, - ); } - +=begin finish sub calculate_ts_mac { state $argcheck = compile( Object,Int, @@ -117,20 +120,6 @@ sub calculate_ts_mac { ); } -sub calc_hmac { - state $argcheck = compile(Object,Str,Algorithm,Str); - my ($self,$data,$algorithm,$key) = $argcheck->(@_); - - state $function_map = { - sha1 => \&hmac_sha1_base64, - sha256 => \&hmac_sha256_base64, - }; - - return _pad_b64($function_map->{$algorithm}->( - $data,$key, - )); -} - sub make_digest { state $argcheck = compile(Object,Algorithm); my ($self,$algorithm) = $argcheck->(@_); |