| 1 |
package DNS::LDNS::Key; |
| 2 |
|
| 3 |
use 5.008008; |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
|
| 7 |
use DNS::LDNS ':all'; |
| 8 |
|
| 9 |
our $VERSION = '0.61'; |
| 10 |
|
| 11 |
sub new { |
| 12 |
my ($class, %args) = @_; |
| 13 |
|
| 14 |
my $key; |
| 15 |
|
| 16 |
if ($args{filename} or $args{file}) { |
| 17 |
my $status = &LDNS_STATUS_OK; |
| 18 |
my $line_nr = 0; |
| 19 |
my $file = $args{file}; |
| 20 |
if ($args{filename}) { |
| 21 |
unless (open FILE, $args{filename}) { |
| 22 |
$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR; |
| 23 |
return; |
| 24 |
} |
| 25 |
$file = \*FILE; |
| 26 |
} |
| 27 |
|
| 28 |
$key = _new_from_file($file, $line_nr, $status); |
| 29 |
if ($args{filename}) { |
| 30 |
close $file; |
| 31 |
} |
| 32 |
|
| 33 |
$DNS::LDNS::last_status = $status; |
| 34 |
$DNS::LDNS::line_nr = $line_nr; |
| 35 |
if (!defined $key) { |
| 36 |
return; |
| 37 |
} |
| 38 |
} |
| 39 |
else { |
| 40 |
$key = _new(); |
| 41 |
} |
| 42 |
|
| 43 |
return $key; |
| 44 |
} |
| 45 |
|
| 46 |
sub set_pubkey_owner { |
| 47 |
my ($self, $owner) = @_; |
| 48 |
my $oldowner = $self->pubkey_owner; |
| 49 |
DNS::LDNS::GC::disown(my $old = $self->pubkey_owner); |
| 50 |
$self->_set_pubkey_owner($owner); |
| 51 |
return DNS::LDNS::GC::own($owner, $self); |
| 52 |
} |
| 53 |
|
| 54 |
sub pubkey_owner { |
| 55 |
my $self = shift; |
| 56 |
return DNS::LDNS::GC::own($self->_pubkey_owner, $self); |
| 57 |
} |
| 58 |
|
| 59 |
sub DESTROY { |
| 60 |
DNS::LDNS::GC::free($_[0]); |
| 61 |
} |
| 62 |
|
| 63 |
1; |
| 64 |
__END__ |
| 65 |
|
| 66 |
=head1 NAME |
| 67 |
|
| 68 |
DNS::LDNS::Key - DNSSec private key |
| 69 |
|
| 70 |
=head1 SYNOPSIS |
| 71 |
|
| 72 |
use DNS::LDNS ':all' |
| 73 |
|
| 74 |
key = new DNS::LDNS::Key |
| 75 |
key = new DNS::LDNS::Key(file => \*FILE) |
| 76 |
key = new DNS::LDNS::Key(filename => 'keyfile') |
| 77 |
|
| 78 |
str = key->to_string |
| 79 |
key->print(\*OUTPUT) |
| 80 |
|
| 81 |
key->set_algorithm(alg) |
| 82 |
alg = key->algorithm |
| 83 |
key->set_flags(flags) |
| 84 |
flags = key->flags |
| 85 |
key->set_hmac_key(hmac) |
| 86 |
hmac = key->hmac_key |
| 87 |
key->set_hmac_size(size) |
| 88 |
size = key->hmac_size |
| 89 |
key->set_origttl(ttl) |
| 90 |
ttl = key->origttl |
| 91 |
key->set_inception(epoch) |
| 92 |
epoch = key->inception |
| 93 |
key->set_expiration(epoch) |
| 94 |
epoch = key->expiration |
| 95 |
key->set_pubkey_owner(rdata) |
| 96 |
rdata = key->pubkey_owner |
| 97 |
key->set_keytag(tag) |
| 98 |
tag = key->keytag |
| 99 |
key->set_use(bool) |
| 100 |
bool = key->use |
| 101 |
|
| 102 |
str = key->get_file_base_name |
| 103 |
|
| 104 |
rr = key->to_rr |
| 105 |
|
| 106 |
=head1 SEE ALSO |
| 107 |
|
| 108 |
http://www.nlnetlabs.nl/projects/ldns |
| 109 |
|
| 110 |
=head1 AUTHOR |
| 111 |
|
| 112 |
Erik Pihl Ostlyngen, E<lt>[email protected]<gt> |
| 113 |
|
| 114 |
=head1 COPYRIGHT AND LICENSE |
| 115 |
|
| 116 |
Copyright (C) 2013 by UNINETT Norid AS |
| 117 |
|
| 118 |
This library is free software; you can redistribute it and/or modify |
| 119 |
it under the same terms as Perl itself, either Perl version 5.14.2 or, |
| 120 |
at your option, any later version of Perl 5 you may have available. |
| 121 |
|
| 122 |
=cut |