aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/DNS-LDNS/lib/DNS/LDNS/Key.pm
blob: bbce173dd8bbe3bb12b464056081517fad1b9524 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package DNS::LDNS::Key;

use 5.008008;
use strict;
use warnings;

use DNS::LDNS ':all';

our $VERSION = '0.06';

sub new {
    my ($class, %args) = @_;

    my $key;

    if ($args{filename} or $args{file}) {
	my $status = &LDNS_STATUS_OK;
	my $line_nr = 0;
	my $file = $args{file};
	if ($args{filename}) {
	    unless (open FILE, $args{filename}) {
		$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
		return;
	    }
	    $file = \*FILE;
	}

	$key = _new_from_file($file, $line_nr, $status);
	if ($args{filename}) {
	    close $file;
	}

	$DNS::LDNS::last_status = $status;
	$DNS::LDNS::line_nr = $line_nr;
	if (!defined $key) {
	    return;
	}
    }
    else {
	$key = _new();
    }

    return $key;
}

sub set_pubkey_owner {
    my ($self, $owner) = @_;
    my $oldowner = $self->pubkey_owner;
    DNS::LDNS::GC::disown(my $old = $self->pubkey_owner);
    $self->_set_pubkey_owner($owner);
    return DNS::LDNS::GC::own($owner, $self);
}

sub pubkey_owner {
    my $self = shift;
    return DNS::LDNS::GC::own($self->_pubkey_owner, $self);
}

sub DESTROY {
    DNS::LDNS::GC::free($_[0]);
}

1;
__END__

=head1 NAME

DNS::LDNS::Key - DNSSec private key

=head1 SYNOPSIS

  use DNS::LDNS ':all'

  key = new DNS::LDNS::Key
  key = new DNS::LDNS::Key(file => \*FILE)
  key = new DNS::LDNS::Key(filename => 'keyfile')

  str = key->to_string
  key->print(\*OUTPUT)

  key->set_algorithm(alg)
  alg = key->algorithm
  key->set_flags(flags)
  flags = key->flags
  key->set_hmac_key(hmac)
  hmac = key->hmac_key
  key->set_hmac_size(size)
  size = key->hmac_size
  key->set_origttl(ttl)
  ttl = key->origttl
  key->set_inception(epoch)
  epoch = key->inception
  key->set_expiration(epoch)
  epoch = key->expiration
  key->set_pubkey_owner(rdata)
  rdata = key->pubkey_owner
  key->set_keytag(tag)
  tag = key->keytag
  key->set_use(bool)
  bool = key->use

  str = key->get_file_base_name

  rr = key->to_rr

=head1 SEE ALSO

http://www.nlnetlabs.nl/projects/ldns

=head1 AUTHOR

Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2013 by UNINETT Norid AS

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.

=cut