.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
.    if \nF \{
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Mail::DKIM::Signer 3"
.TH Mail::DKIM::Signer 3 "2010-11-14" "perl v5.16.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Mail::DKIM::Signer \- generates a DKIM signature for a message
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\&  use Mail::DKIM::Signer;
\&  use Mail::DKIM::TextWrap;  #recommended
\&
\&  # create a signer object
\&  my $dkim = Mail::DKIM::Signer\->new(
\&                  Algorithm => "rsa\-sha1",
\&                  Method => "relaxed",
\&                  Domain => "example.org",
\&                  Selector => "selector1",
\&                  KeyFile => "private.key",
\&             );
\&
\&  # read an email from a file handle
\&  $dkim\->load(*STDIN);
\&
\&  # or read an email and pass it into the signer, one line at a time
\&  while (<STDIN>)
\&  {
\&      # remove local line terminators
\&      chomp;
\&      s/\e015$//;
\&
\&      # use SMTP line terminators
\&      $dkim\->PRINT("$_\e015\e012");
\&  }
\&  $dkim\->CLOSE;
\&
\&  # what is the signature result?
\&  my $signature = $dkim\->signature;
\&  print $signature\->as_string;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This class is the part of Mail::DKIM responsible for generating
signatures for a given message. You create an object of this class,
specifying the parameters of the signature you wish to create, or
specifying a callback function so that the signature parameters can
be determined later. Next, you feed it the entire message using
\&\*(L"\s-1\fIPRINT\s0()\fR\*(R", completing with \*(L"\s-1\fICLOSE\s0()\fR\*(R". Finally, use the
\&\*(L"\fIsignatures()\fR\*(R" method to access the generated signatures.
.SS "Pretty Signatures"
.IX Subsection "Pretty Signatures"
Mail::DKIM includes a signature-wrapping module (which inserts
linebreaks into the generated signature so that it looks nicer in the
resulting message. To enable this module, simply call
.PP
.Vb 1
\&  use Mail::DKIM::TextWrap;
.Ve
.PP
in your program before generating the signature.
.SH "CONSTRUCTOR"
.IX Header "CONSTRUCTOR"
.SS "\fInew()\fP"
.IX Subsection "new()"
Construct an object-oriented signer.
.PP
.Vb 8
\&  # create a signer using the default policy
\&  my $dkim = Mail::DKIM::Signer\->new(
\&                  Algorithm => "rsa\-sha1",
\&                  Method => "relaxed",
\&                  Domain => "example.org",
\&                  Selector => "selector1",
\&                  KeyFile => "private.key",
\&             );
\&
\&  # create a signer using a custom policy
\&  my $dkim = Mail::DKIM::Signer\->new(
\&                  Policy => $policyfn,
\&             );
.Ve
.PP
The \*(L"default policy\*(R" is to create a \s-1DKIM\s0 signature using the specified
parameters, but only if the message's sender matches the domain.
The following parameters can be passed to this \fInew()\fR method to
influence the resulting signature:
Algorithm, Method, Domain, Selector, KeyFile, Identity, Timestamp.
.PP
If you want different behavior, you can provide a \*(L"signer policy\*(R"
instead. A signer policy is a subroutine or class that determines
signature parameters after the message's headers have been parsed.
See the section \*(L"\s-1SIGNER POLICIES\*(R"\s0 below for more information.
.PP
See Mail::DKIM::SignerPolicy for more information about policy objects.
.PP
In addition to the parameters demonstrated above, the following
are recognized:
.IP "Key" 4
.IX Item "Key"
rather than using \f(CW\*(C`KeyFile\*(C'\fR, use \f(CW\*(C`Key\*(C'\fR to use an already-loaded
Mail::DKIM::PrivateKey object.
.SH "METHODS"
.IX Header "METHODS"
.SS "\s-1\fIPRINT\s0()\fP"
.IX Subsection "PRINT()"
Feed part of the message to the signer.
.PP
.Vb 1
\&  $dkim\->PRINT("a line of the message\e015\e012");
.Ve
.PP
Feeds content of the message being signed into the signer.
The \s-1API\s0 is designed this way so that the entire message does \s-1NOT\s0 need
to be read into memory at once.
.PP
Please note that although the \s-1\fIPRINT\s0()\fR method expects you to use
SMTP-style line termination characters, you should \s-1NOT\s0 use the
SMTP-style dot-stuffing technique described in \s-1RFC 2821\s0 section 4.5.2.
Nor should you use a <\s-1CR\s0><\s-1LF\s0>.<\s-1CR\s0><\s-1LF\s0> sequence to terminate the
message.
.SS "\s-1\fICLOSE\s0()\fP"
.IX Subsection "CLOSE()"
Call this when finished feeding in the message.
.PP
.Vb 1
\&  $dkim\->CLOSE;
.Ve
.PP
This method finishes the canonicalization process, computes a hash,
and generates a signature.
.SS "\fIadd_signature()\fP"
.IX Subsection "add_signature()"
Used by signer policy to create a new signature.
.PP
.Vb 1
\&  $dkim\->add_signature(new Mail::DKIM::Signature(...));
.Ve
.PP
Signer policies can use this method to specify complete parameters for
the signature to add, including what type of signature. For more information,
see Mail::DKIM::SignerPolicy.
.SS "\fIalgorithm()\fP"
.IX Subsection "algorithm()"
Get or set the selected algorithm.
.PP
.Vb 1
\&  $alg = $dkim\->algorithm;
\&
\&  $dkim\->algorithm("rsa\-sha1");
.Ve
.SS "\fIdomain()\fP"
.IX Subsection "domain()"
Get or set the selected domain.
.PP
.Vb 1
\&  $alg = $dkim\->domain;
\&
\&  $dkim\->domain("example.org");
.Ve
.SS "\fIload()\fP"
.IX Subsection "load()"
Load the entire message from a file handle.
.PP
.Vb 1
\&  $dkim\->load($file_handle);
.Ve
.PP
Reads a complete message from the designated file handle,
feeding it into the signer.  The message must use <\s-1CRLF\s0> line
terminators (same as the \s-1SMTP\s0 protocol).
.SS "\fIheaders()\fP"
.IX Subsection "headers()"
Determine which headers to put in signature.
.PP
.Vb 1
\&  my $headers = $dkim\->headers;
.Ve
.PP
This is a string containing the names of the header fields that
will be signed, separated by colons.
.SS "\fIkey()\fP"
.IX Subsection "key()"
Get or set the private key object.
.PP
.Vb 1
\&  my $key = $dkim\->key;
\&
\&  $dkim\->key(Mail::DKIM::PrivateKey\->load(File => "private.key"));
.Ve
.PP
The key object can be any object that implements the
\&\fIsign_digest()\fR method.
(Providing your own object can be useful if your actual keys
are stored out-of-process.)
.PP
If you use this method to specify a private key,
do not use \*(L"\fIkey_file()\fR\*(R".
.SS "\fIkey_file()\fP"
.IX Subsection "key_file()"
Get or set the filename containing the private key.
.PP
.Vb 1
\&  my $filename = $dkim\->key_file;
\&
\&  $dkim\->key_file("private.key");
.Ve
.PP
If you use this method to specify a private key file,
do not use \*(L"\fIkey()\fR\*(R".
.SS "\fImethod()\fP"
.IX Subsection "method()"
Get or set the selected canonicalization method.
.PP
.Vb 1
\&  $alg = $dkim\->method;
\&
\&  $dkim\->method("relaxed");
.Ve
.SS "\fImessage_originator()\fP"
.IX Subsection "message_originator()"
Access the \*(L"From\*(R" header.
.PP
.Vb 1
\&  my $address = $dkim\->message_originator;
.Ve
.PP
Returns the \*(L"originator address\*(R" found in the message, as a
Mail::Address object.
This is typically the (first) name and email address found in the
From: header. If there is no From: header,
then an empty Mail::Address object is returned.
.PP
To get just the email address part, do:
.PP
.Vb 1
\&  my $email = $dkim\->message_originator\->address;
.Ve
.PP
See also \*(L"\fImessage_sender()\fR\*(R".
.SS "\fImessage_sender()\fP"
.IX Subsection "message_sender()"
Access the \*(L"From\*(R" or \*(L"Sender\*(R" header.
.PP
.Vb 1
\&  my $address = $dkim\->message_sender;
.Ve
.PP
Returns the \*(L"sender\*(R" found in the message, as a Mail::Address object.
This is typically the (first) name and email address found in the
Sender: header. If there is no Sender: header, it is the first name and
email address in the From: header. If neither header is present,
then an empty Mail::Address object is returned.
.PP
To get just the email address part, do:
.PP
.Vb 1
\&  my $email = $dkim\->message_sender\->address;
.Ve
.PP
The \*(L"sender\*(R" is the mailbox of the agent responsible for the actual
transmission of the message. For example, if a secretary were to send a
message for another person, the \*(L"sender\*(R" would be the secretary and
the \*(L"originator\*(R" would be the actual author.
.SS "\fIselector()\fP"
.IX Subsection "selector()"
Get or set the current key selector.
.PP
.Vb 1
\&  $alg = $dkim\->selector;
\&
\&  $dkim\->selector("alpha");
.Ve
.SS "\fIsignature()\fP"
.IX Subsection "signature()"
Access the generated signature object.
.PP
.Vb 1
\&  my $signature = $dkim\->signature;
.Ve
.PP
Returns the generated signature. The signature is an object of type
Mail::DKIM::Signature. If multiple signatures were generated, this method
returns the last one.
.PP
The signature (as text) should be \fBprepended\fR to the message to make the
resulting message. At the very least, it should precede any headers
that were signed.
.SS "\fIsignatures()\fP"
.IX Subsection "signatures()"
Access list of generated signature objects.
.PP
.Vb 1
\&  my @signatures = $dkim\->signatures;
.Ve
.PP
Returns all generated signatures, as a list.
.SH "SIGNER POLICIES"
.IX Header "SIGNER POLICIES"
The \fInew()\fR constructor takes an optional Policy argument. This
can be a Perl object or class with an \fIapply()\fR method, or just a simple
subroutine reference. The method/subroutine will be called with the
signer object as an argument. The policy is responsible for checking the
message and specifying signature parameters. The policy must return a
nonzero value to create the signature, otherwise no signature will be
created. E.g.,
.PP
.Vb 2
\&  my $policyfn = sub {
\&      my $dkim = shift;
\&
\&      # specify signature parameters
\&      $dkim\->algorithm("rsa\-sha1");
\&      $dkim\->method("relaxed");
\&      $dkim\->domain("example.org");
\&      $dkim\->selector("mx1");
\&
\&      # return true value to create the signature
\&      return 1;
\&  };
.Ve
.PP
Or the policy object can actually create the signature, using the
add_signature method within the policy object.
If you add a signature, you do not need to return a nonzero value.
This mechanism can be utilized to create multiple signatures,
or to create the older DomainKey-style signatures.
.PP
.Vb 10
\&  my $policyfn = sub {
\&      my $dkim = shift;
\&      $dkim\->add_signature(
\&              new Mail::DKIM::Signature(
\&                      Algorithm => "rsa\-sha1",
\&                      Method => "relaxed",
\&                      Headers => $dkim\->headers,
\&                      Domain => "example.org",
\&                      Selector => "mx1",
\&              ));
\&      $dkim\->add_signature(
\&              new Mail::DKIM::DkSignature(
\&                      Algorithm => "rsa\-sha1",
\&                      Method => "nofws",
\&                      Headers => $dkim\->headers,
\&                      Domain => "example.org",
\&                      Selector => "mx1",
\&              ));
\&      return;
\&  };
.Ve
.PP
If no policy is specified, the default policy is used. The default policy
signs every message using the domain, algorithm, method, and selector
specified in the \fInew()\fR constructor.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Mail::DKIM::SignerPolicy
.SH "AUTHOR"
.IX Header "AUTHOR"
Jason Long, <jlong@messiah.edu>
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
Copyright (C) 2006\-2007 by Messiah College
.PP
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.
