diff options
author | dakkar <dakkar@thenautilus.net> | 2014-12-28 17:55:17 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2014-12-28 17:55:17 +0000 |
commit | c38481cb9f06bf85e29b7676370468d56cdc858a (patch) | |
tree | e5b868db19a85567f6f3f0896b157b1e80b06330 /lib/Net/Hawk/Crypto.pm | |
parent | fix auth header parsing (diff) | |
download | net-hawk-c38481cb9f06bf85e29b7676370468d56cdc858a.tar.gz net-hawk-c38481cb9f06bf85e29b7676370468d56cdc858a.tar.bz2 net-hawk-c38481cb9f06bf85e29b7676370468d56cdc858a.zip |
everything ported to p6
Diffstat (limited to 'lib/Net/Hawk/Crypto.pm')
-rw-r--r-- | lib/Net/Hawk/Crypto.pm | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/lib/Net/Hawk/Crypto.pm b/lib/Net/Hawk/Crypto.pm index 1cd5a8d..240a6f7 100644 --- a/lib/Net/Hawk/Crypto.pm +++ b/lib/Net/Hawk/Crypto.pm @@ -14,7 +14,7 @@ package Net::Hawk::Crypto { }; multi generate_normalized_string( Str:D :$type!, - URI:D :$resource!, + URI :$resource, Int:D :$ts!, Str:D :$nonce!, Str :$method, @@ -32,7 +32,7 @@ package Net::Hawk::Crypto { $ts, $nonce, uc($method // ''), - $resource.path_query, + ( $resource ?? $resource.path_query !! ''), lc($host), $port, $hash // '', @@ -86,52 +86,29 @@ 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, $algorithm, $key, ); - } - -} -=begin finish -sub calculate_ts_mac { - state $argcheck = compile( - Object,Int, - Dict[ - algorithm => Algorithm, - key => Str, - slurpy Any, - ], - ); - my ($self,$ts,$credentials) = $argcheck->(@_); - - my $string = sprintf( - "hawk.%s.ts\n%d\n", - header_version(), - $ts, - ); - - return $self->calc_hmac( - $string, - $credentials->{algorithm}, - $credentials->{key}, - ); -} - -sub make_digest { - state $argcheck = compile(Object,Algorithm); - my ($self,$algorithm) = $argcheck->(@_); - - return Digest::SHA->new($algorithm =~ s{^sha}{}r); -} + }; -sub _pad_b64 { - my ($b64) = @_; + sub calculate_ts_mac( + Int:D $ts, + Hash:D $credentials ( Str :$algorithm, Str :$key, *% ), + ) returns Str is export { + my $string = sprintf( + "hawk.%s.ts\n%d\n", + header_version(), + $ts, + ); - $b64 .= '=' while length($b64) % 4; - return $b64; + return calc_hmac( + $string, + $algorithm, + $key, + ); + } } - -1; |