line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NIST::Beacon; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A Perl module for querying NIST's randomness beacon. |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
71827
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
142
|
|
6
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
192
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "1.001"; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
2074
|
use Moo; |
|
4
|
|
|
|
|
49780
|
|
|
4
|
|
|
|
|
18
|
|
11
|
4
|
|
|
4
|
|
9382
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use LWP::UserAgent; |
13
|
|
|
|
|
|
|
use NIST::Beacon::Record; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _agent => (is => 'ro', default => sub { LWP::UserAgent->new(agent => 'NIST-Beacon') }); |
16
|
|
|
|
|
|
|
has _url => (is => 'ro', default => sub { 'https://beacon.nist.gov/rest/record/' }); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub latest_record { |
19
|
|
|
|
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
my $url = $self->_url . 'last'; |
21
|
|
|
|
|
|
|
my $response = $self->_agent->get($url); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if ($response->is_success) { |
24
|
|
|
|
|
|
|
my $data = XMLin($response->decoded_content); |
25
|
|
|
|
|
|
|
return NIST::Beacon::Record->new($data); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
|
|
|
|
|
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub previous_record { |
33
|
|
|
|
|
|
|
my $self = shift; |
34
|
|
|
|
|
|
|
my $time = shift || time; |
35
|
|
|
|
|
|
|
my $url = $self->_url . 'previous/' . $time; |
36
|
|
|
|
|
|
|
my $response = $self->_agent->get($url); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ($response->is_success) { |
39
|
|
|
|
|
|
|
my $data = XMLin($response->decoded_content); |
40
|
|
|
|
|
|
|
return NIST::Beacon::Record->new($data); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub current_record { |
48
|
|
|
|
|
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
my $time = shift || time - 60; |
50
|
|
|
|
|
|
|
my $url = $self->_url . $time; |
51
|
|
|
|
|
|
|
my $response = $self->_agent->get($url); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if ($response->is_success) { |
54
|
|
|
|
|
|
|
my $data = XMLin($response->decoded_content); |
55
|
|
|
|
|
|
|
return NIST::Beacon::Record->new($data); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub next_record { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
my $time = shift or return; |
65
|
|
|
|
|
|
|
my $url = $self->_url . 'next/' . $time; |
66
|
|
|
|
|
|
|
my $response = $self->_agent->get($url); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
if ($response->is_success) { |
69
|
|
|
|
|
|
|
my $data = XMLin($response->decoded_content); |
70
|
|
|
|
|
|
|
return NIST::Beacon::Record->new($data); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
|
|
|
|
|
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |