| 1 | package Mail::DKIM::Key; | ||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 20 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | # ABSTRACT: Represents a DKIM Key | ||||||||||
| 5 | 20 | our $VERSION = '1.20261116'; # VERSION | |||||||||
| 6 | |||||||||||
| 7 | # Copyright 2006 Jason Long. All rights reserved. | ||||||||||
| 8 | # | ||||||||||
| 9 | # Copyright (c) 2004 Anthony D. Urso. All rights reserved. | ||||||||||
| 10 | # This program is free software; you can redistribute it and/or | ||||||||||
| 11 | # modify it under the same terms as Perl itself. | ||||||||||
| 12 | |||||||||||
| 13 | 1493 | ▶ | sub cork { | ||||||||
|
Subroutine
cork: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 14 | 1493 | my $self = shift; | |||||||||
| 15 | |||||||||||
| 16 | (@_) | ||||||||||
| 17 | 1493 | ▶ | and $self->{'CORK'} = shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 1493 | ▶ | $self->{'CORK'} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | or $self->convert; | ||||||||||
| 21 | |||||||||||
| 22 | 1492 | $self->{'CORK'}; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 1152 | ▶ | sub data { | ||||||||
|
Subroutine
data: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 26 | 1152 | my $self = shift; | |||||||||
| 27 | |||||||||||
| 28 | (@_) | ||||||||||
| 29 | 1152 | ▶ | and $self->{'DATA'} = shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | |||||||||||
| 31 | 1152 | $self->{'DATA'}; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub errorstr { | ||||||||
|
Subroutine
errorstr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 35 | 0 | my $self = shift; | |||||||||
| 36 | |||||||||||
| 37 | (@_) | ||||||||||
| 38 | 0 | ▶ | and $self->{'ESTR'} = shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 0 | $self->{'ESTR'}; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub size { | ||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 44 | 0 | my $self = shift; | |||||||||
| 45 | |||||||||||
| 46 | 0 | return $self->cork->size * 8; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub type { | ||||||||
|
Subroutine
type: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 50 | 0 | my $self = shift; | |||||||||
| 51 | |||||||||||
| 52 | (@_) | ||||||||||
| 53 | 0 | ▶ | and $self->{'TYPE'} = shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | 0 | $self->{'TYPE'}; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 398 | ▶ | sub calculate_EM { | ||||||||
|
Subroutine
calculate_EM: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||
| 59 | 398 | my ( $digest_algorithm, $digest, $emLen ) = @_; | |||||||||
| 60 | |||||||||||
| 61 | # this function performs DER encoding of the algorithm ID for the | ||||||||||
| 62 | # hash function and the hash value itself | ||||||||||
| 63 | # It has this syntax: | ||||||||||
| 64 | # DigestInfo ::= SEQUENCE { | ||||||||||
| 65 | # digestAlgorithm AlgorithmIdentifier, | ||||||||||
| 66 | # digest OCTET STRING | ||||||||||
| 67 | # } | ||||||||||
| 68 | |||||||||||
| 69 | # RFC 3447, page 42, provides the following octet values: | ||||||||||
| 70 | 398 | my %digest_encoding = ( | |||||||||
| 71 | 'SHA-1' => pack( 'H*', '3021300906052B0E03021A05000414' ), | ||||||||||
| 72 | 'SHA-256' => pack( 'H*', '3031300d060960864801650304020105000420' ), | ||||||||||
| 73 | ); | ||||||||||
| 74 | |||||||||||
| 75 | 398 | ▶ | defined $digest_encoding{$digest_algorithm} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | or die "Unsupported digest algorithm '$digest_algorithm'"; | ||||||||||
| 77 | |||||||||||
| 78 | 398 | my $T = $digest_encoding{$digest_algorithm} . $digest; | |||||||||
| 79 | 398 | my $tLen = length($T); | |||||||||
| 80 | |||||||||||
| 81 | 398 | ▶ | if ( $emLen < $tLen + 11 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | die 'Intended encoded message length too short.'; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 398 | my $PS = chr(0xff) x ( $emLen - $tLen - 3 ); | |||||||||
| 86 | 398 | my $EM = chr(0) . chr(1) . $PS . chr(0) . $T; | |||||||||
| 87 | 398 | return $EM; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 20 | 1; | |||||||||
| 91 | |||||||||||
| 92 | __END__ | ||||||||||