| 1 | package Crypt::JWS::OpenSSL::Role::Encoder; | ||||||||||
| 2 | 5 | $Crypt::JWS::OpenSSL::Role::Encoder::VERSION = '0.005'; | |||||||||
| 3 | 5 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use MIME::Base64 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use JSON::MaybeXS 1.002002 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use Carp qw( croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use version 0.78; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 24 | ▶ | has 'JSON' => ( is => 'ro', default => sub { JSON::MaybeXS->new->utf8(1) } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 985 | ▶ | sub parse_params { | ||||||||
|
Subroutine
parse_params: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 12 | 985 | my $self = shift; | |||||||||
| 13 | 985 | my %params; | |||||||||
| 14 | 985 | ▶ | if ( @_ % 2 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 432 | ▶ | if ( ref $_[0] eq 'HASH' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 432 | %params = %{ shift() }; | |||||||||
| 17 | } else { | ||||||||||
| 18 | 0 | croak('Expecting a HASH ref or a list of key-value pairs'); | |||||||||
| 19 | } | ||||||||||
| 20 | } | ||||||||||
| 21 | else { | ||||||||||
| 22 | 553 | %params = @_; | |||||||||
| 23 | } | ||||||||||
| 24 | 985 | return ( $self, \%params ); | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 438 | ▶ | sub encode_jwt_segment { | ||||||||
|
Subroutine
encode_jwt_segment: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 28 | 438 | my($self, $ref) = @_; | |||||||||
| 29 | 438 | my $bytes = $self->JSON->encode($ref); | |||||||||
| 30 | 438 | my $base64 = MIME::Base64::encode_base64($bytes, ''); | |||||||||
| 31 | 438 | $base64 =~ s!=+\z!!; | |||||||||
| 32 | 438 | $base64 =~ tr[+/][-_]; | |||||||||
| 33 | 438 | return $base64; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 224 | ▶ | sub decode_jwt_segment { | ||||||||
|
Subroutine
decode_jwt_segment: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 37 | 224 | my($self, $base64) = @_; | |||||||||
| 38 | 224 | $base64 =~ tr[-_][+/]; | |||||||||
| 39 | 224 | ▶ | $base64 .= '=' while length($base64) % 4; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 224 | my $json = MIME::Base64::decode_base64($base64); | |||||||||
| 41 | 224 | return $self->JSON->decode($json); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 306 | ▶ | sub encode_jwt_signature { | ||||||||
|
Subroutine
encode_jwt_signature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 45 | 306 | my($self, $bytes) = @_; | |||||||||
| 46 | 306 | return $self->encode_base64_url($bytes); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 210 | ▶ | sub decode_jwt_signature { | ||||||||
|
Subroutine
decode_jwt_signature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 50 | 210 | my($self, $base64) = @_; | |||||||||
| 51 | 210 | return $self->decode_base64_url($base64); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub encode_jwk_element { | ||||||||
|
Subroutine
encode_jwk_element: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 55 | 0 | my($self, $bytes) = @_; | |||||||||
| 56 | 0 | return $self->encode_base64_url($bytes); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 102 | ▶ | sub decode_jwk_element { | ||||||||
|
Subroutine
decode_jwk_element: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 60 | 102 | my($self, $base64) = @_; | |||||||||
| 61 | 102 | return $self->decode_base64_url($base64); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 306 | ▶ | sub encode_base64_url { | ||||||||
|
Subroutine
encode_base64_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 65 | 306 | my($self, $bytes) = @_; | |||||||||
| 66 | 306 | my $base64 = $self->encode_base64($bytes); | |||||||||
| 67 | 306 | $base64 =~ s!=+\z!!; | |||||||||
| 68 | 306 | $base64 =~ tr[+/][-_]; | |||||||||
| 69 | 306 | return $base64; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 312 | ▶ | sub encode_base64 { | ||||||||
|
Subroutine
encode_base64: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 73 | 312 | my($self, $bytes) = @_; | |||||||||
| 74 | 312 | return MIME::Base64::encode_base64($bytes, ''); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 312 | ▶ | sub decode_base64_url { | ||||||||
|
Subroutine
decode_base64_url: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | 312 | my($self, $base64) = @_; | |||||||||
| 79 | 312 | $base64 =~ tr[-_][+/]; | |||||||||
| 80 | 312 | ▶ | $base64 .= '=' while length($base64) % 4; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 312 | return $self->decode_base64($base64); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 361 | ▶ | sub decode_base64 { | ||||||||
|
Subroutine
decode_base64: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 85 | 361 | my($self, $base64) = @_; | |||||||||
| 86 | 361 | return MIME::Base64::decode_base64($base64); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | sub encode_rsa_private_key_pem { | ||||||||
|
Subroutine
encode_rsa_private_key_pem: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 90 | 0 | my($self, $bytes) = @_; | |||||||||
| 91 | 0 | return $self->_encode_pem(\$bytes, 'PRIVATE KEY'); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | sub encode_rsa_public_key_pem { | ||||||||
|
Subroutine
encode_rsa_public_key_pem: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 95 | 0 | my($self, $bytes) = @_; | |||||||||
| 96 | 0 | return $self->_encode_pem(\$bytes, 'PUBLIC KEY'); | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 3 | ▶ | sub encode_ecc_private_key_pem { | ||||||||
|
Subroutine
encode_ecc_private_key_pem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 100 | 3 | my($self, $bytes) = @_; | |||||||||
| 101 | 3 | return $self->_encode_pem(\$bytes, 'EC PRIVATE KEY'); | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 3 | ▶ | sub encode_ecc_public_key_pem { | ||||||||
|
Subroutine
encode_ecc_public_key_pem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 105 | 3 | my($self, $bytes) = @_; | |||||||||
| 106 | 3 | return $self->_encode_pem(\$bytes, 'PUBLIC KEY'); | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 6 | ▶ | sub _encode_pem { | ||||||||
|
Subroutine
_encode_pem: called CC=1 SCAR=0.0
| |||||||||||
| 110 | 6 | my ($self, $bytes_ref, $type) = @_; | |||||||||
| 111 | 6 | my $pem = $self->encode_base64($$bytes_ref); | |||||||||
| 112 | 6 | $pem = join( qq(\n), $pem =~ m!(.{1,64})!g, '' ); | |||||||||
| 113 | 6 | substr( $pem, 0, 0, "-----BEGIN $type-----\n" ); | |||||||||
| 114 | 6 | substr( $pem, length($pem), 0, "-----END $type-----\n" ); | |||||||||
| 115 | 6 | return $pem; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 48 | ▶ | sub decode_pem { | ||||||||
|
Subroutine
decode_pem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 119 | 48 | my ($self, $pem) = @_; | |||||||||
| 120 | 48 | $pem =~ s!-----(BEGIN|END)[^-]*-----!!g; | |||||||||
| 121 | 48 | return $self->decode_base64($pem); | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 23 | ▶ | sub numify_version { | ||||||||
|
Subroutine
numify_version: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 125 | 23 | my ($self, $vstring) = @_; | |||||||||
| 126 | 5 | ▶ | no warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 127 | 23 | my $ver = version->parse($vstring)->numify; | |||||||||
| 128 | 23 | return $ver; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 5 | 1; | |||||||||
| 132 | |||||||||||
| 133 | __END__ | ||||||||||