Commits

Toby Inkster committed d2a87f7 Draft

improve unicode support

Comments (0)

Files changed (8)

lib/RDF/Crypt/Decrypter.pm

 	$RDF::Crypt::Decrypter::VERSION   = '0.002';
 }
 
-sub decrypt_text
+sub decrypt_bytes
 {
 	my ($self, $text) = @_;
 	$text = decode_base64($text);
 	return substr($text, 0, (length $text) - $removal_chars);
 }
 
-sub encrypt_text
+sub encrypt_bytes
 {
 	my ($self, $text) = @_;
 	encode_base64(

lib/RDF/Crypt/Encrypter.pm

 	$RDF::Crypt::Encrypter::VERSION   = '0.002';
 }
 
-sub encrypt_text
+sub encrypt_bytes
 {
 	my ($self, $text) = @_;
 	
 	my $key = $self->public_keys->[-1];
-	confess('Public key too small. Must be at least 128 bytes.') unless $key->size > 127;
+	confess('Public key too small. Must be at least 64 bytes.') unless $key->size >= 64;
 	
 	my $block_size = $key->size - 16;
 	my $v = my $iv = random_bytes($block_size);
 	
-	my ($scrambled, $last_length);
+	my ($scrambled, $last_length) = ('', 0);
 	while (length $text)
 	{
 		my $block   = substr($text, 0, $block_size);

lib/RDF/Crypt/Role/DoesDecrypt.pm

 use 5.010;
 use Any::Moose 'Role';
 
+use Encode qw(decode);
 use RDF::TrineX::Functions -shortcuts;
 
 use namespace::clean;
 	$RDF::Crypt::Role::DoesDecrypt::VERSION   = '0.002';
 }
 
-requires 'decrypt_text';
+requires 'decrypt_bytes';
+
+sub decrypt_text
+{
+	my ($self, $text) = @_;
+	decode(
+		'utf-8',
+		$self->decrypt_bytes($text),
+	);
+}
 
 sub decrypt_model
 {

lib/RDF/Crypt/Role/DoesEncrypt.pm

 
 use Crypt::OpenSSL::Bignum qw[];
 use Crypt::OpenSSL::RSA qw[];
+use Encode qw(encode);
 use File::Slurp qw[slurp];
 use Mail::Message qw[];
 use Mail::Transport::Send qw[];
 	$RDF::Crypt::Role::DoesEncrypt::VERSION   = '0.002';
 }
 
-requires 'encrypt_text';
+requires 'encrypt_bytes';
+
+sub encrypt_text
+{
+	my ($self, $text) = @_;
+	$self->encrypt_bytes(
+		encode('utf-8', $text),
+	);
+}
 
 sub encrypt_model
 {

lib/RDF/Crypt/Role/DoesSign.pm

 use 5.010;
 use Any::Moose 'Role';
 
+use Encode qw(encode);
 use RDF::TrineX::Functions -shortcuts;
 
 use namespace::clean;
 	$RDF::Crypt::Role::DoesSign::VERSION   = '0.002';
 }
 
-requires 'sign_text';
+requires 'sign_bytes';
 requires 'SIG_MARK';
 
+sub sign_text
+{
+	my ($self, $text) = @_;
+	$self->sign_bytes(
+		encode('utf-8', $text),
+	);
+}
+
 sub generate_manifest
 {
 	my ($self, $my_webid, $uris) = @_;

lib/RDF/Crypt/Role/DoesVerify.pm

 use 5.010;
 use Any::Moose 'Role';
 
+use Encode qw(encode);
 use RDF::TrineX::Functions -shortcuts;
 use RDF::Query;
 
 	$RDF::Crypt::Role::DoesVerify::VERSION   = '0.002';
 }
 
-requires 'verify_text';
+requires 'verify_bytes';
 requires 'SIG_MARK';
 
+sub verify_text
+{
+	my ($self, $text, $signature) = @_;
+	$self->verify_bytes($text, $signature);
+}
+
 sub verify_manifest
 {
 	my ($class, $data, %opts) = @_;

lib/RDF/Crypt/Signer.pm

 	$RDF::Crypt::Signer::VERSION   = '0.002';
 }
 
-sub sign_text
+sub sign_bytes
 {
 	my ($self, $text) = @_;
 	encode_base64(
 	);
 }
 
-sub verify_text
+sub verify_bytes
 {
 	my ($self, $text, $signature) = @_;
 	!!$self->private_key->verify(

lib/RDF/Crypt/Verifier.pm

 	$RDF::Crypt::Verifier::VERSION   = '0.002';
 }
 
-sub verify_text
+sub verify_bytes
 {
 	my ($self, $text, $signature) = @_;