1package Crypt::Perl::Ed25519::PublicKey;
2
3use strict;
4use warnings;
5
6=encoding utf-8
7
8=head1 NAME
9
10Crypt::Perl::Ed25519::PublicKey
11
12=head1 SYNOPSIS
13
14    # This requires an octet string.
15    my $import_key = Crypt::Perl::Ed25519::PublicKey->new( $pub_str );
16
17    $key->verify( $message, $signature ) or die "Invalid sig for msg!";
18
19    #----------------------------------------------------------------------
20
21    # Returns an octet string.
22    my $pub_str = $key->get_public();
23
24    # Returns an object
25    my $pub_obj = $key->get_public_key();
26
27    # This returns a hash reference, NOT a JSON string.
28    my $pub_hr = $key->get_struct_for_public_jwk();
29
30=head1 DESCRIPTION
31
32This class implements Ed25519 verification.
33
34=cut
35
36use parent qw( Crypt::Perl::Ed25519::KeyBase );
37
38sub new {
39    my ($class, $pub) = @_;
40
41    $class->_verify_binary_key_part($pub);
42
43    return bless {
44        _public => $pub,
45        _public_ar => [ unpack 'C*', $pub ],
46    }, $class;
47}
48
49use constant {
50    _PEM_HEADER => 'PUBLIC KEY',
51    _ASN1 => q<
52        FG_Key ::= SEQUENCE {
53            algorithmIdentifier AlgorithmIdentifier,
54            subjectPublicKey    BIT STRING
55        }
56    >,
57};
58
59sub _to_der_args {
60    my ($self) = @_;
61
62    return (
63
64        # The leading bytes are the encoding of the inner CurvePrivateKey
65        # (i.e., OCTET STRING).
66        subjectPublicKey => $self->{'_public'},
67    );
68}
69
701;
71