Source

p5-rdf-crypt / lib / RDF / Crypt / Signer.pm

package RDF::Crypt::Signer;

use 5.010;
use Any::Moose;
with qw(
	RDF::Crypt::Role::WithPrivateKey
	RDF::Crypt::Role::DoesVerify
	RDF::Crypt::Role::DoesSign	
	RDF::Crypt::Role::StandardSignatureMarkers
	RDF::Crypt::Role::ToString
);

use MIME::Base64 qw(
	encode_base64
	decode_base64
);

use namespace::clean;

BEGIN {
	$RDF::Crypt::Signer::AUTHORITY = 'cpan:TOBYINK';
	$RDF::Crypt::Signer::VERSION   = '0.002';
}

sub sign_bytes
{
	my ($self, $text) = @_;
	encode_base64(
		$self->private_key->sign($text),
		q(),
	);
}

sub verify_bytes
{
	my ($self, $text, $signature) = @_;
	!!$self->private_key->verify(
		$text,
		decode_base64($signature),
	);
}

1;

__END__

=head1 NAME

RDF::Crypt::Signer - signs RDF graphs with RSA

=head1 DESCRIPTION

A Signer object is created using an RSA private key. The object can be used
to sign multiple RDF graphs. The signature should be independent of the RDF
serialisation used, so that Turtle and RDF/XML files containing equivalent
triples should generate the same signature.

RDF::Crypt::Signer can also be used to verify signatures using the private
key of the signer.

=head2 Roles

=over

=item * L<RDF::Crypt::Role::WithPrivateKey>

=item * L<RDF::Crypt::Role::DoesSign>

=item * L<RDF::Crypt::Role::DoesVerify>

=item * L<RDF::Crypt::Role::StandardSignatureMarkers>

=item * L<RDF::Crypt::Role::ToString>

=back

=begin trustme

=item * sign_bytes

=item * verify_bytes

=item * SIG_MARK

=end trustme

=head1 SEE ALSO

L<RDF::Crypt>,
L<RDF::Crypt::Verifier>.

=head1 BUGS

Please report any bugs to L<http://rt.cpan.org/>.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT

Copyright 2010, 2012 Toby Inkster

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.