Add ARM files
[dh-make-perl] / dev / arm / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / debian / libnet-ssleay-perl / usr / share / doc / libnet-ssleay-perl / examples / bio.pl
1 #!/usr/local/bin/perl -w
2 # bio.pl mikem@open.com.au
3 #
4 # Test and demonstrate BIO interface
5
6 use Net::SSLeay qw(die_now);
7
8 $data = '0123456789' x 100;
9 $len = length($data);
10
11 $b = &Net::SSLeay::BIO_new(&Net::SSLeay::BIO_s_mem())
12     or die_now("Could not create memory BIO $!");
13
14 &Net::SSLeay::BIO_write($b, $data)
15     or die_now("Could not write memory BIO $!");
16
17 # Should now have 1000 bytes in BIO
18 $pending =  &Net::SSLeay::BIO_pending($b);
19 die("Incorrect result from BIO_pending: $pending. Should be $len")
20     unless $pending == $len;
21
22 # Partial read of 9 bytes
23 $len = 9;
24 $part = &Net::SSLeay::BIO_read($b, $len);
25 $nlen = length($part);
26 die("Incorrect result from BIO_read: $len. Should be 9")
27     unless $nlen == $len;
28
29 die("Incorrect data from BIO_read: $len. Should be 012345678")
30     unless $part eq '012345678';
31
32 # Should be 991 bytes left
33 $len = 991;
34 $pending =  &Net::SSLeay::BIO_pending($b);
35 die("Incorrect result from BIO_pending: $pending. Should be $len")
36     unless $pending == $len;
37
38 # Read the rest
39 $part = &Net::SSLeay::BIO_read($b);
40 $nlen = length($part);
41 die("Incorrect result from BIO_read: $len. Should be 991")
42     unless $len == $nlen;
43
44 &Net::SSLeay::BIO_free($b);
45
46 print "OK\n";
47 exit;