File Coverage

lib/Crypt/RSA/Errorhandler.pm
Criterion Covered Total %
statement 18 18 100.0
branch 7 8 87.5
condition n/a
subroutine 5 5 100.0
pod 4 4 100.0
total 34 35 97.1


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -sw
2             ##
3             ## Crypt::RSA::Errorhandler -- Base class that provides error
4             ## handling functionality.
5             ##
6             ## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved.
7             ## This code is free software; you can redistribute it and/or modify
8             ## it under the same terms as Perl itself.
9             ##
10             ## $Id: Errorhandler.pm,v 1.5 2001/06/22 23:27:35 vipul Exp $
11              
12             package Crypt::RSA::Errorhandler;
13 13     13   237 use strict;
  13         217  
  13         282  
14              
15             sub new {
16 1     1 1 69     bless {}, shift
17             }
18              
19              
20             sub error {
21 203     203 1 4105     my ($self, $errstr, @towipe) = @_;
22 203         2414     $$self{errstr} = "$errstr\n";
23 203         2036     for (@towipe) {
24 803         6874         my $var = $_;
25 803 100       12167         if (ref($var) =~ /Crypt::RSA/) {
    100          
    100          
    50          
26 200         2476             $var->DESTROY();
27                     } elsif (ref($var) eq "SCALAR") {
28 401         4088             $$var = "";
29                     } elsif (ref($var) eq "ARRAY") {
30 1         11             @$var = ();
31                     } elsif (ref($var) eq "HASH") {
32 201         2861             %$var = ();
33                     }
34                 }
35 203         4487     return;
36             } 
37              
38              
39             sub errstr {
40 12     12 1 114     my $self = shift;
41 12         211     return $$self{errstr};
42             }
43              
44             sub errstrrst {
45 339     339 1 3222     my $self = shift;
46 339         8486     $$self{errstr} = "";
47             }
48              
49             1;
50              
51              
52             =head1 NAME
53            
54             Crypt::RSA::Errorhandler - Error handling mechanism for Crypt::RSA.
55            
56             =head1 SYNOPSIS
57            
58             package Foo;
59            
60             use Crypt::RSA::Errorhandler;
61             @ISA = qw(Crypt::RSA::Errorhandler);
62            
63             sub alive {
64             ..
65             ..
66             return
67             $self->error ("Awake, awake! Ring the alarum bell. \
68             Murther and treason!", $dagger)
69             if $self->murdered($king);
70             }
71            
72            
73             package main;
74            
75             use Foo;
76             my $foo = new Foo;
77             $foo->alive($king) or print $foo->errstr();
78             # prints "Awake, awake! ... "
79            
80             =head1 DESCRIPTION
81            
82             Crypt::RSA::Errorhandler encapsulates the error handling mechanism used
83             by the modules in Crypt::RSA bundle. Crypt::RSA::Errorhandler doesn't
84             have a constructor and is meant to be inherited. The derived modules use
85             its two methods, error() and errstr(), to communicate error messages to
86             the caller.
87            
88             When a method of the derived module fails, it calls $self->error() and
89             returns undef to the caller. The error message passed to error() is made
90             available to the caller through the errstr() accessor. error() also
91             accepts a list of sensitive data that it wipes out (undef'es) before
92             returning.
93            
94             The caller should B<never> call errstr() to check for errors. errstr()
95             should be called only when a method indicates (usually through an undef
96             return value) that an error has occured. This is because errstr() is
97             never overwritten and will always contain a value after the occurance of
98             first error.
99            
100             =head1 METHODS
101            
102             =over 4
103            
104             =item B<new()>
105            
106             Barebones constructor.
107            
108             =item B<error($mesage, ($wipeme, $wipemetoo))>
109            
110             The first argument to error() is $message which is placed in $self-
111             >{errstr} and the remaining arguments are interpretted as
112             variables containing sensitive data that are wiped out from the
113             memory. error() always returns undef.
114            
115             =item B<errstr()>
116            
117             errstr() is an accessor method for $self->{errstr}.
118            
119             =item B<errstrrst()>
120            
121             This method sets $self->{errstr} to an empty string.
122            
123             =back
124            
125             =head1 AUTHOR
126            
127             Vipul Ved Prakash, E<lt>mail@vipul.netE<gt>
128            
129             =head1 SEE ALSO
130            
131             Crypt::RSA(3)
132            
133             =cut
134              
135              
136