+ $self->__Set( Field => 'ContentType', Value => $type );
+ $self->SetHeader( 'Content-Type' => $type );
+
+ my $content = $self->Content;
+ my %res = RT::Crypt::GnuPG::SignEncryptContent(
+ Content => \$content,
+ Sign => 0,
+ Encrypt => 1,
+ Recipients => [ $encrypt_for ],
+ );
+ if ( $res{'exit_code'} ) {
+ return (0, $self->loc('GnuPG error. Contact with administrator'));
+ }
+
+ my ($status, $msg) = $self->__Set( Field => 'Content', Value => $content );
+ unless ( $status ) {
+ return ($status, $self->loc("Couldn't replace content with encrypted data: [_1]", $msg));
+ }
+ return (1, $self->loc('Successfuly encrypted data'));
+}
+
+sub Decrypt {
+ my $self = shift;
+
+ my $txn = $self->TransactionObj;
+ return (0, $self->loc('Permission Denied')) unless $txn->CurrentUserCanSee;
+ return (0, $self->loc('Permission Denied'))
+ unless $txn->TicketObj->CurrentUserHasRight('ModifyTicket');
+ return (0, $self->loc('GnuPG integration is disabled'))
+ unless RT->Config->Get('GnuPG')->{'Enable'};
+
+ require RT::Crypt::GnuPG;
+
+ my $type = $self->ContentType;
+ if ( $type =~ /^x-application-rt\/gpg-encrypted/i ) {
+ ($type) = ($type =~ /original-type="(.*)"/i);
+ $type ||= 'application/octeat-stream';
+ } else {
+ return (1, $self->loc('Is not encrypted'));
+ }
+ $self->__Set( Field => 'ContentType', Value => $type );
+ $self->SetHeader( 'Content-Type' => $type );
+
+ my $content = $self->Content;
+ my %res = RT::Crypt::GnuPG::DecryptContent( Content => \$content, );
+ if ( $res{'exit_code'} ) {
+ return (0, $self->loc('GnuPG error. Contact with administrator'));
+ }
+
+ my ($status, $msg) = $self->__Set( Field => 'Content', Value => $content );
+ unless ( $status ) {
+ return ($status, $self->loc("Couldn't replace content with decrypted data: [_1]", $msg));