RC4: Converting to text template

master
Rob Emery 2016-05-18 20:57:34 +01:00
parent e71eb3c5d4
commit 1ccc31c175
2 changed files with 23 additions and 17 deletions

View File

@ -43,11 +43,14 @@ handle remainder => sub {
return;
}
return "$operation: $plaintext, with key: $key is $result",
structured_answer => {
operation => $operation,
input => [html_enc($plaintext) . ", Key: $key"],
result => $result
return "$operation: $plaintext, with key: $key is $result", structured_answer => {
data => {
title => html_enc($result),
subtitle => "$operation: " . html_enc($plaintext) . ", Key: $key"
},
templates => {
group => 'text'
}
};
};

27
t/Rc4.t
View File

@ -9,22 +9,25 @@ use DDG::Test::Goodie;
zci answer_type => "rc4";
zci is_cached => 1;
sub build_test {
my ($text, $title, $subtitle) = @_;
return test_zci($text, structured_answer => {
data => {
title => $title,
subtitle => $subtitle
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test(
[qw(
DDG::Goodie::Rc4
)],
'rc4 en mysecretkey hello' => test_zci("RC4 Encrypt: hello, with key: mysecretkey is grYU1K8=",
structured_answer => {
input => ['hello, Key: mysecretkey'],
operation => "RC4 Encrypt",
result => "grYU1K8="
}),
'rc4 de duck yWrJniG/nNg=' => test_zci("RC4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks",
structured_answer => {
input => ['yWrJniG/nNg=, Key: duck'],
operation => "RC4 Decrypt",
result => "DdgRocks"
}),
'rc4 en mysecretkey hello' => build_test("RC4 Encrypt: hello, with key: mysecretkey is grYU1K8=", "grYU1K8=", "RC4 Encrypt: hello, Key: mysecretkey"),
'rc4 de duck yWrJniG/nNg=' => build_test("RC4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks", "DdgRocks", "RC4 Decrypt: yWrJniG/nNg=, Key: duck"),
'rc4 ' => undef,
'rc4 enc missing' => undef,
'rc4 no operation' => undef