~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/contrib/perl-xs/t/base64.t

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
10
BEGIN { $| = 1; print "1..24\n"; }
 
11
END { print "not ok 1\n" unless $loaded; }
 
12
 
 
13
require 't/testutl.pl';
 
14
use Botan;
 
15
 
 
16
$loaded = 1;
 
17
print "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
 
 
25
use strict;
 
26
 
 
27
# Data prep
 
28
 
 
29
my $botan_lic_b64_garbage = <<'EOF';
 
30
Q29weXJpZ2h0IChDKSAxOTk5LTIwMDQgVGhlIEJvdGFuIFByb2plY3QuIEFsbCBy__�
 
31
aWdodHMgcmVzZXJ2ZWQuCgpSZWRpc3RyaWJ1dGlvbiBhbmQgdXNlIGluIHNvdXJj$$*:
 
32
ZSBhbmQgYmluYXJ5IGZvcm1zLCBmb3IgYW55IHVzZSwgd2l0aCBvciB3aXRob3V0!@#$%^&*(
 
33
Cm1vZGlmaWNhdGlvbiwgaXMgcGVybWl0dGVkIHByb3ZpZGVkIHRoYXQgdGhlIGZv[\]
 
34
bGxvd2luZyBjb25kaXRpb25zIGFyZSBtZXQ6CgoxL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QgVE8sIFBST0NVUkVN
 
50
RU5UIE9GIFNVQlNUSVRVVEUgR09PRFMgT1IgU0VSVklDRVM7IExPU1MgT0YgVVNF
 
51
LApEQVRBLCBPUiBQUk9GSVRTOyBPUiBCVVNJTkVTUyBJTlRFUlJVUFRJT04pIEhP
 
52
V0VWRVIgQ0FVU0VEIEFORCBPTiBBTlkgVEhFT1JZIE9GCkxJQUJJTElUWSwgV0hF
 
53
VEhFUiBJTiBDT05UUkFDVCwgU1RSSUNUIExJQUJJTElUWSwgT1IgVE9SVCAoSU5D
 
54
TFVESU5HIE5FR0xJR0VOQ0UKT1IgT1RIRVJXSVNFKSBBUklTSU5HIElOIEFOWSBX
 
55
QVkgT1VUIE9GIFRIRSBVU0UgT0YgVEhJUyBTT0ZUV0FSRSwgRVZFTiBJRgpBRFZJ
 
56
U0VEIE9GIFRIRSBQT1NTSUJJTElUWSBPRiBTVUNIIERBTUFHRS4K
 
57
EOF
 
58
 
 
59
my $botan_lic_b64_ws = $botan_lic_b64_garbage;
 
60
$botan_lic_b64_ws =~ s/[^A-Za-z0-9+\/= \n]//g;
 
61
 
 
62
my $botan_lic_b64 = $botan_lic_b64_ws;
 
63
$botan_lic_b64 =~ s/[ \n]//g;
 
64
 
 
65
 
 
66
my $botan_lic = <<'EOF';
 
67
Copyright (C) 1999-2004 The Botan Project. All rights reserved.
 
68
 
 
69
Redistribution and use in source and binary forms, for any use, with or without
 
70
modification, is permitted provided that the following conditions are met:
 
71
 
 
72
1. Redistributions of source code must retain the above copyright notice, this
 
73
list of conditions, and the following disclaimer.
 
74
 
 
75
2. Redistributions in binary form must reproduce the above copyright notice,
 
76
this list of conditions, and the following disclaimer in the documentation
 
77
and/or other materials provided with the distribution.
 
78
 
 
79
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
 
80
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
81
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
 
82
 
 
83
IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
 
84
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
85
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
86
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
87
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
88
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
89
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
90
EOF
 
91
 
 
92
 
 
93
# Decoder...
 
94
 
 
95
my $f;
 
96
 
 
97
eval { $f = Botan::Base64_Decoder->new(&Botan::NONE); };
 
98
print "not " if $@ || !defined $f;
 
99
print "ok 2\n";
 
100
 
 
101
my $dec;
 
102
eval { $dec = Botan::Pipe->new($f); };
 
103
print "not " if $@ || !defined $dec;
 
104
print "ok 3\n";
 
105
 
 
106
eval { $f = Botan::Base64_Decoder->new(&Botan::IGNORE_WS); };
 
107
print "not " if $@ || !defined $f;
 
108
print "ok 4\n";
 
109
 
 
110
my $dec_is;
 
111
eval { $dec_is = Botan::Pipe->new($f); };
 
112
print "not " if $@ || !defined $dec_is;
 
113
print "ok 5\n";
 
114
 
 
115
eval { $f = Botan::Base64_Decoder->new(&Botan::FULL_CHECK); };
 
116
print "not " if $@ || !defined $f;
 
117
print "ok 6\n";
 
118
 
 
119
my $dec_fc;
 
120
eval { $dec_fc = Botan::Pipe->new($f); };
 
121
print "not " if $@ || !defined $dec_fc;
 
122
print "ok 7\n";
 
123
 
 
124
 
 
125
# Testing clean base64 input
 
126
 
 
127
my $data;
 
128
 
 
129
undef $data;
 
130
eval {
 
131
    $dec->process_msg($botan_lic_b64);
 
132
    $data = $dec->read();
 
133
};
 
134
 
 
135
print "not " if $@ || $data ne $botan_lic;
 
136
print "ok 8\n";
 
137
 
 
138
undef $data;
 
139
eval {
 
140
    $dec_is->process_msg($botan_lic_b64);
 
141
    $data = $dec_is->read();
 
142
};
 
143
 
 
144
print "not " if $@ || $data ne $botan_lic;
 
145
print "ok 9\n";
 
146
 
 
147
undef $data;
 
148
eval {
 
149
    $dec_fc->process_msg($botan_lic_b64);
 
150
    $data = $dec_fc->read();
 
151
};
 
152
 
 
153
print "not " if $@ || $data ne $botan_lic;
 
154
print "ok 10\n";
 
155
 
 
156
 
 
157
# Testing base64 input with whitespaces
 
158
 
 
159
undef $data;
 
160
eval {
 
161
    $dec->process_msg($botan_lic_b64_ws);
 
162
    $dec->set_default_msg(1);
 
163
    $data = $dec->read();
 
164
};
 
165
 
 
166
print "not " if $@ || $data ne $botan_lic;
 
167
print "ok 11\n";
 
168
 
 
169
undef $data;
 
170
eval {
 
171
    $dec_is->process_msg($botan_lic_b64_ws);
 
172
    $dec_is->set_default_msg(1);
 
173
    $data = $dec_is->read();
 
174
};
 
175
 
 
176
print "not " if $@ || $data ne $botan_lic;
 
177
print "ok 12\n";
 
178
 
 
179
undef $data;
 
180
eval {
 
181
    $dec_fc->process_msg($botan_lic_b64_ws);
 
182
    $dec_fc->set_default_msg(1);
 
183
    $data = $dec_fc->read();
 
184
};
 
185
 
 
186
print "not " unless $@ && !defined $data;
 
187
print "ok 13\n";
 
188
 
 
189
 
 
190
# Testing base64 input with garbage
 
191
 
 
192
undef $data;
 
193
eval {
 
194
    $dec->process_msg($botan_lic_b64_garbage);
 
195
    $dec->set_default_msg(2);
 
196
    $data = $dec->read();
 
197
};
 
198
 
 
199
print "not " if $@ || $data ne $botan_lic;
 
200
print "ok 14\n";
 
201
 
 
202
undef $data;
 
203
eval {
 
204
    $dec_is->process_msg($botan_lic_b64_garbage);
 
205
    $dec_is->set_default_msg(2);
 
206
    $data = $dec_is->read();
 
207
};
 
208
 
 
209
print "not " unless $@ && !defined $data;
 
210
print "ok 15\n";
 
211
 
 
212
undef $data;
 
213
eval {
 
214
    $dec_fc->process_msg($botan_lic_b64_garbage);
 
215
    $dec_fc->set_default_msg(2);
 
216
    $data = $dec_fc->read();
 
217
};
 
218
 
 
219
print "not " unless $@ && !defined $data;
 
220
print "ok 16\n";
 
221
 
 
222
 
 
223
# Encoder...
 
224
 
 
225
eval { $f = Botan::Base64_Encoder->new(); };
 
226
print "not " if $@ || !defined $f;
 
227
print "ok 17\n";
 
228
 
 
229
my $enc;
 
230
eval { $enc = Botan::Pipe->new($f); };
 
231
print "not " if $@ || !defined $enc;
 
232
print "ok 18\n";
 
233
 
 
234
eval { $f = Botan::Base64_Encoder->new(1, 5); };
 
235
print "not " if $@ || !defined $f;
 
236
print "ok 19\n";
 
237
 
 
238
my $enc2;
 
239
eval { $enc2 = Botan::Pipe->new($f); };
 
240
print "not " if $@ || !defined $enc2;
 
241
print "ok 20\n";
 
242
 
 
243
undef $data;
 
244
eval {
 
245
    $enc->process_msg("Hello\n");
 
246
    $data = $enc->read();
 
247
};
 
248
print "not " if $@ || $data ne "SGVsbG8K";
 
249
print "ok 21\n";
 
250
 
 
251
undef $data;
 
252
eval {
 
253
    $enc2->process_msg("Hello\n");
 
254
    $data = $enc2->read();
 
255
};
 
256
print "not " if $@ || $data ne "SGVsb\nG8K\n";
 
257
print "ok 22\n";
 
258
 
 
259
 
 
260
# Encoder with decoder...
 
261
 
 
262
my $p;
 
263
eval {
 
264
    $p = Botan::Pipe->new(
 
265
            Botan::Base64_Encoder->new(),
 
266
            Botan::Base64_Decoder->new(),
 
267
        );
 
268
};
 
269
print "not " if $@ || !defined $p;
 
270
print "ok 23\n";
 
271
 
 
272
print "not " unless random_message_ok($p);
 
273
print "ok 24\n";