Authen-U2F-Tester

 view release on metacpan or  search on metacpan

lib/Authen/U2F/Tester/Keystore/Wrapped.pm  view on Meta::CPAN

#
# This file is part of Authen-U2F-Tester
#
# This software is copyright (c) 2017 by Michael Schout.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
package Authen::U2F::Tester::Keystore::Wrapped;
$Authen::U2F::Tester::Keystore::Wrapped::VERSION = '0.03';
# ABSTRACT: Wrapped Keystore for Authen::U2F::Tester

use Moose;
use Crypt::PK::ECC;
use MIME::Base64 qw(decode_base64url);
use namespace::autoclean;

with 'Authen::U2F::Tester::Role::Keystore';

has key => (is => 'ro', isa => 'Crypt::PK::ECC', required => 1);

sub exists {
    my ($self, $handle) = @_;

    $handle = decode_base64url($handle);

    if (eval { $self->key->decrypt($handle); 1 }) {
        return 1;
    }
    else {
        return 0;
    }
}

sub get {
    my ($self, $handle) = @_;

    my $private_key = $self->key->decrypt(decode_base64url($handle));

    my $pkec = Crypt::PK::ECC->new;
    $pkec->import_key_raw($private_key, 'nistp256');

    return $pkec;
}

sub put {
    my ($self, $private_key) = @_;

    my $handle = $self->key->encrypt($private_key, 'SHA256');

    return $handle;
}

sub remove {
    require Carp;
    Carp::croak 'Keys cannot be removed from the Wrapped Keystore';
}

__PACKAGE__->meta->make_immutable;

__END__

=pod

=head1 NAME

Authen::U2F::Tester::Keystore::Wrapped - Wrapped Keystore for Authen::U2F::Tester

=head1 VERSION

version 0.03

=head1 SYNOPSIS

 my $key = Crypt::PK::ECC->new;
 ...



( run in 1.178 second using v1.01-cache-2.11-cpan-5a3173703d6 )