Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/ng-compat'
- Loading branch information
Showing
36 changed files
with
180 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,49 +1,13 @@ | |||
module Digest; | module Digest; | ||
|
|
||
# Known digests: md5, sha1, sha256, sha512, ripemd160 | use Digest::MD5; | ||
sub digest(Str $text, Str $algo is copy = 'md5') is export { | use Digest::SHA; | ||
$algo = uc $algo; | |||
my $binary = Q:PIR { | |||
.local string text | |||
.local string algo | |||
.local pmc digest | |||
# Input | |||
$P0 = find_lex '$text' | |||
text = $P0 | |||
$P0 = find_lex '$algo' | |||
algo = $P0 | |||
# Choose the right digest. | |||
$P1 = loadlib 'digest_group' | |||
if algo == 'MD5' goto MD5 | |||
if algo == 'SHA1' goto SHA1 | |||
if algo == 'SHA256' goto SHA256 | |||
if algo == 'SHA512' goto SHA512 | |||
if algo == 'RIPEMD160' goto RIPEMD160 | |||
MD5: | |||
digest = new 'MD5' | |||
goto COMPUTE | |||
SHA1: | |||
digest = new 'SHA1' | |||
goto COMPUTE | |||
SHA256: | |||
digest = new 'SHA256' | |||
goto COMPUTE | |||
SHA512: | |||
digest = new 'SHA512' | |||
goto COMPUTE | |||
RIPEMD160: | |||
digest = new 'RIPEMD160' | |||
|
|
||
COMPUTE: | # Known digests: md5, sha1, sha256, sha512, ripemd160 | ||
# Calculate the digest. | sub digest(Str $text, Str $algo = 'md5') is export { | ||
digest.'Init'() | given $algo { | ||
digest.'Update'(text) | when 'md5' { return Digest::MD5.md5_hex($text) } | ||
$S0 = digest.'Final'() | when 'sha256' { return Digest::SHA.sha256_hex($text) } | ||
|
default { !!! "digest for $algo not yet implemented" } | ||
%r = box $S0 | } | ||
}; | |||
# Convert to hex. | |||
return [~] map { sprintf '%02x', .ord }, $binary.comb; | |||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
class Digest::SHA:auth<thou>:ver<0.01> { | |||
pir::load_bytecode('Digest/sha256.pbc'); | |||
|
|||
multi method sha256_hex (Str $str) { | |||
my $sha256_hex = Q:PIR { | |||
.local pmc f, g, str | |||
str = find_lex '$str' | |||
f = get_root_global ['parrot'; 'Digest'], '_sha256sum' | |||
$P1 = f(str) | |||
g = get_root_global ['parrot'; 'Digest'], '_sha256_hex' | |||
$S0 = g($P1) | |||
%r = box $S0 | |||
}; | |||
return $sha256_hex; | |||
} | |||
multi method sha256_hex (@strs) { | |||
return self.sha256_hex(@strs.join("")); | |||
} | |||
} | |||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.