| 1 | package WWW::LetsEncrypt::JWA; | ||
| 2 | 10 | $WWW::LetsEncrypt::JWA::VERSION = '0.001'; | |
| 3 | 10 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 10 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 10 | ▶ | use Carp qw(confess); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 10 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 10 | ▶ | use Moose::Util::TypeConstraints; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 10 | has 'alg' => ( | |
| 12 | is => 'ro', | ||
| 13 | isa => enum([qw(RS256 RS384 RS512 ES256 ESA384 ES512)]), | ||
| 14 | required => 1, | ||
| 15 | ); | ||
| 16 | |||
| 17 | |||
| 18 | # '_hash' a private scalar attribute meant to hold the hashing algorithm | ||
| 19 | # that will be used when signing or generating the thumbprint. | ||
| 20 | |||
| 21 | 10 | has '_hash' => ( | |
| 22 | is => 'rw', | ||
| 23 | isa => 'Str', | ||
| 24 | init_arg => undef, | ||
| 25 | lazy => 1, | ||
| 26 | builder => '_build__hash' | ||
| 27 | ); | ||
| 28 | |||
| 29 | 10 | requires 'sign'; | |
| 30 | 10 | requires '_set_hash'; | |
| 31 | |||
| 32 | sub _build__hash { | ||
| 33 | 7 | ▶ | my ($self) = @_; |
|
Subroutine
_build__hash: called CC=1 SCAR=0.0
| |||
| 34 | 7 | my ($hash) = $self->alg =~ m/(\d+)$/; | |
| 35 | 7 | return "sha$hash"; | |
| 36 | } | ||
| 37 | |||
| 38 | 10 | 1; | |
| 39 | __END__ | ||
| 40 | |||
| 41 | |||
| 42 | =pod | ||
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | WWW::LetsEncrypt::JWA | ||
| 47 | |||
| 48 | =head1 SYNOPSIS | ||
| 49 | |||
| 50 | use Moose; | ||
| 51 | |||
| 52 | with qw(WWW::LetsEncrypt::JWA ...) | ||
| 53 | |||
| 54 | sub sign { | ||
| 55 | my ($self, $message) = @_; | ||
| 56 | ... | ||
| 57 | return ...; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub _set_hash { | ||
| 61 | ... | ||
| 62 | } | ||
| 63 | |||
| 64 | =head1 DESCRIPTION | ||
| 65 | |||
| 66 | This is a role that when used together with WWW::LetsEncrypt::JWK as parents | ||
| 67 | will create a JSON Web Key that implements all the functions needed for signing | ||
| 68 | JSON Web Signature objects. | ||
| 69 | |||
| 70 | =head2 Attributes | ||
| 71 | |||
| 72 | 'alg' a scalar attribute meant to hold the algorithm that will be used for | ||
| 73 | signing, as defined in the JWA RFC. | ||
| 74 | |||
| 75 | Currently allowed algorithms: | ||
| 76 | ES256, ES384, ES512, | ||
| 77 | RS256, RS384, RS512, | ||
| 78 | |||
| 79 | |||
| 80 | =head2 Public Functions | ||
| 81 | |||
| 82 | =over 4 | ||
| 83 | |||
| 84 | =item sign($message) | ||
| 85 | |||
| 86 | Abstract object function that takes an argument and signs it based off of the | ||
| 87 | internal configuration of the JWA subclass. | ||
| 88 | |||
| 89 | Input | ||
| 90 | |||
| 91 | $self - Object Reference | ||
| 92 | $message - scalar string of what needs to be signed | ||
| 93 | |||
| 94 | Output | ||
| 95 | |||
| 96 | scalar octets representing the signature of the message. | ||
| 97 | |||
| 98 | =back | ||
| 99 | |||
| 100 | =head2 Private Functions | ||
| 101 | |||
| 102 | =over 4 | ||
| 103 | |||
| 104 | =item _set_hash($hash) | ||
| 105 | |||
| 106 | Abstract object function that takes a number argument, which is used to | ||
| 107 | determine which SHA2 algorithm will be used for hashing. | ||
| 108 | |||
| 109 | Implementers should permit values of (256, 384, 512). All other values should | ||
| 110 | throw an error. | ||
| 111 | |||
| 112 | Input | ||
| 113 | |||
| 114 | $self - Object Reference | ||
| 115 | $hash - numerical value | ||
| 116 | |||
| 117 | Output | ||
| 118 | |||
| 119 | boolean if setting the value was successful | ||
| 120 | |||
| 121 | =item _verify_alg($alg) | ||
| 122 | |||
| 123 | Trigger function that is called after the 'alg' parameter has been set. | ||
| 124 | Assuming an accept algorithm was used, this function calls $self->_set_hash | ||
| 125 | with the SHA2 hashing algorithm selected. | ||
| 126 | |||
| 127 | =back | ||
| 128 | |||
| 129 | =cut | ||
| 130 | |||