1# vim: set ft=perl: 2# Before `make install' is performed this script should be runnable with 3# `make test'. After `make install' it should work as `perl test.pl' 4 5######################### We start with some black magic to print on failure. 6 7# Change 1..1 below to 1..last_test_to_print . 8# (It may become useful if the test is moved to ./t subdirectory.) 9 10BEGIN { $| = 1; print "1..24\n"; } 11END { print "not ok 1\n" unless $loaded; } 12 13require 't/testutl.pl'; 14use Botan; 15 16$loaded = 1; 17print "ok 1\n"; 18 19######################### End of black magic. 20 21# Insert your test code below (better if it prints "ok 13" 22# (correspondingly "not ok 13") depending on the success of chunk 13 23# of the test code): 24 25use strict; 26 27# Data prep 28 29my ($hex, $hex_ws, $hex_garbage); 30while ( $_ = <DATA> ) 31{ 32 $hex_garbage .= $_; 33 s/[^[:xdigit:][:space:]]//g; 34 $hex_ws .= $_; 35 s/[^[:xdigit:]]//g; 36 $hex .= $_; 37} 38my $data_test = pack("H*", $hex); 39 40# Decoder... 41 42my $f; 43 44eval { $f = Botan::Hex_Decoder->new(&Botan::NONE); }; 45print "not " if $@ || !defined $f; 46print "ok 2\n"; 47 48my $dec; 49eval { $dec = Botan::Pipe->new($f); }; 50print "not " if $@ || !defined $dec; 51print "ok 3\n"; 52 53eval { $f = Botan::Hex_Decoder->new(&Botan::IGNORE_WS); }; 54print "not " if $@ || !defined $f; 55print "ok 4\n"; 56 57my $dec_is; 58eval { $dec_is = Botan::Pipe->new($f); }; 59print "not " if $@ || !defined $dec_is; 60print "ok 5\n"; 61 62eval { $f = Botan::Hex_Decoder->new(&Botan::FULL_CHECK); }; 63print "not " if $@ || !defined $f; 64print "ok 6\n"; 65 66my $dec_fc; 67eval { $dec_fc = Botan::Pipe->new($f); }; 68print "not " if $@ || !defined $dec_fc; 69print "ok 7\n"; 70 71 72# Testing clean hexadecimal input 73 74my $data; 75 76undef $data; 77eval { 78 $dec->process_msg($hex); 79 $data = $dec->read(); 80}; 81 82print "not " if $@ || $data ne $data_test; 83print "ok 8\n"; 84 85undef $data; 86eval { 87 $dec_is->process_msg($hex); 88 $data = $dec_is->read(); 89}; 90 91print "not " if $@ || $data ne $data_test; 92print "ok 9\n"; 93 94undef $data; 95eval { 96 $dec_fc->process_msg($hex); 97 $data = $dec_fc->read(); 98}; 99 100print "not " if $@ || $data ne $data_test; 101print "ok 10\n"; 102 103 104# Testing hexadecimal input with whitespaces 105 106undef $data; 107eval { 108 $dec->process_msg($hex_ws); 109 $dec->set_default_msg(1); 110 $data = $dec->read(); 111}; 112 113print "not " if $@ || $data ne $data_test; 114print "ok 11\n"; 115 116undef $data; 117eval { 118 $dec_is->process_msg($hex_ws); 119 $dec_is->set_default_msg(1); 120 $data = $dec_is->read(); 121}; 122 123print "not " if $@ || $data ne $data_test; 124print "ok 12\n"; 125 126undef $data; 127eval { 128 $dec_fc->process_msg($hex_ws); 129 $dec_fc->set_default_msg(1); 130 $data = $dec_fc->read(); 131}; 132 133print "not " unless $@ && !defined $data; 134print "ok 13\n"; 135 136 137# Testing hexadecimal input with garbage 138 139undef $data; 140eval { 141 $dec->process_msg($hex_garbage); 142 $dec->set_default_msg(2); 143 $data = $dec->read(); 144}; 145 146print "not " if $@ || $data ne $data_test; 147print "ok 14\n"; 148 149undef $data; 150eval { 151 $dec_is->process_msg($hex_garbage); 152 $dec_is->set_default_msg(2); 153 $data = $dec_is->read(); 154}; 155 156print "not " unless $@ && !defined $data; 157print "ok 15\n"; 158 159undef $data; 160eval { 161 $dec_fc->process_msg($hex_garbage); 162 $dec_fc->set_default_msg(2); 163 $data = $dec_fc->read(); 164}; 165 166print "not " unless $@ && !defined $data; 167print "ok 16\n"; 168 169 170# Encoder... 171 172eval { $f = Botan::Hex_Encoder->new(); }; 173print "not " if $@ || !defined $f; 174print "ok 17\n"; 175 176my $enc; 177eval { $enc = Botan::Pipe->new($f); }; 178print "not " if $@ || !defined $enc; 179print "ok 18\n"; 180 181eval { $f = Botan::Hex_Encoder->new(1, 5, 1); }; 182print "not " if $@ || !defined $f; 183print "ok 19\n"; 184 185my $enc2; 186eval { $enc2 = Botan::Pipe->new($f); }; 187print "not " if $@ || !defined $enc2; 188print "ok 20\n"; 189 190undef $data; 191eval { 192 $enc->process_msg("Hello\n"); 193 $data = $enc->read(); 194}; 195print "not " if $@ || $data ne "48656C6C6F0A"; 196print "ok 21\n"; 197 198undef $data; 199eval { 200 $enc2->process_msg("Hello\n"); 201 $data = $enc2->read(); 202}; 203print "not " if $@ || $data ne "48656\nc6c6f\n0a\n"; 204print "ok 22\n"; 205 206 207# Encoder with decoder... 208 209my $p; 210eval { 211 $p = Botan::Pipe->new( 212 Botan::Hex_Encoder->new(), 213 Botan::Hex_Decoder->new(), 214 ); 215}; 216print "not " if $@ || !defined $p; 217print "ok 23\n"; 218 219print "not " unless random_message_ok($p); 220print "ok 24\n"; 221 222 223 224__DATA__ 225cb13 4a4d 7522 1fd3 c6f6 7786 d04b 3043 ..JMu"....w..K.. 2264552 4bcf 4d2b 9d71 0cfe 4d6a 1caf bcfd .RK.M+.q..Mj.... 2278f91 6151 ff85 e900 7e6a bafc 15e9 ae51 ...Q....~j.....Q 228b14b 7210 bb40 5958 2b82 d49e b808 68a5 .Kr..@YX+.....h. 2297945 9dec f686 9b98 989e 826d 8088 6ee7 y..........m..n. 230d066 1eac 8c34 c461 bb54 7726 87ab d681 .........Tw&.... 231a0be 52e5 1128 0cf2 759e cb2d e690 4ed9 ..R..(..u..-..N. 2327e88 bda7 2523 4a0f 185a 02b1 f898 fc41 ~...%#J..Z...... 233dd48 fa87 945d 7611 b8c9 a50a 2de2 b670 .H...]v.....-..p 2340056 c8be 2cbb e7d0 1e70 4a3d 79f0 dce9 .V..,....pJ=y... 235b57f 154b 2b3a db73 f086 de11 9f3e 1641 ...K+:.s.....>.. 2363a28 8b9b bb0f 682b 80db b791 89e0 62c0 :(....h+........ 2377204 db97 5432 2eb0 a04e f38e 809f 7223 r...T....N....r# 238912e e552 1452 6dd2 e09f dd06 c715 7c1a ...R.Rm.......|. 239fe3d d6cc b6d0 a17a 27d7 4327 4e43 8af3 .=.....z'..'N... 2406eb5 e9f8 bfe9 34c3 6636 8243 358f 966d n..............m 2417d87 d17b 5c37 6acb 4972 f4ec 6806 bbde }..{\.j.Ir..h... 2422689 a019 a9e2 4101 7fe2 de72 bc03 eb5e &..........r...^ 243b699 2d6b f8cd a08e 6e01 edfc a81a 94b6 ..-k....n....... 2449073 15fb efb2 c8d9 9f85 6633 85f1 e9d0 .s.............. 24520ce 578b ab9d 2e51 b947 69bf fba5 82c6 .W....Q.Gi..... 2462ed0 dd36 d679 a399 7db3 8a0d cdef 0eda .....y..}....... 247e761 e7f1 5b17 3f67 0c83 215a eddf 9d2a ....[.?g..!Z...* 2485e70 0a77 c92e 94e1 a82b fd7c f10a 894f ^p.w.....+.|...O 2492955 f0e8 7398 f409 2040 b797 da03 a5a6 )U..s... @...... 2507ba4 c3c9 2659 b9f7 6a56 e17a b481 983f {...&Y..jV.z...? 25100ed 3cc8 5a22 ad5c b6e0 3566 d717 35a6 ..<.Z".\........ 2521523 4104 de63 477e fd24 68e5 e816 98df .#....G~.$h..... 2531747 417e db72 a76a be5b b9dc 3dfb 2d05 .G.~.r.j.[..=.-. 254d27f e597 eafc 9a29 15c5 792d 9c88 9aea .......)..y-.... 255485e e431 96c3 7723 da6d 28b2 477a fd12 H^....w#.m(.Gz.. 256e645 5dcd 7d5a d8b4 7acc 10b2 b41a e11d ..].}Z..z....... 257