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