File: 31_rsa_generate_key.t

package info (click to toggle)
libnet-ssleay-perl 1.36-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 940 kB
  • ctags: 798
  • sloc: perl: 3,668; ansic: 2,711; makefile: 7
file content (73 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;
use Net::SSLeay;

eval 'use Test::Exception';
plan skip_all => 'Test::Exception required' if $@;

plan tests => 14;

Net::SSLeay::randomize();
Net::SSLeay::load_error_strings();
Net::SSLeay::ERR_load_crypto_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();

lives_ok(sub {
        Net::SSLeay::RSA_generate_key(512, 0x10001);
}, 'RSA_generate_key with valid callback');

dies_ok(sub {
        Net::SSLeay::RSA_generate_key(512, 0x10001, 1);
}, 'RSA_generate_key with invalid callback');

{
    my $called = 0;

    lives_ok(sub {
            Net::SSLeay::RSA_generate_key(512, 0x10001, \&cb);
    }, 'RSA_generate_key with valid callback');

    cmp_ok( $called, '>', 0, 'callback has been called' );

    sub cb {
        my ($i, $n, $d) = @_;

        if ($called == 0) {
            is( wantarray(), undef, 'RSA_generate_key callback is executed in void context' );
            is( $d, undef, 'userdata will be undef if no userdata was given' );

            ok( defined $i, 'first argument is defined' );
            ok( defined $n, 'second argument is defined' );
        }

        $called++;
    }
}

{
    my $called   = 0;
    my $userdata = 'foo';

    lives_ok(sub {
            Net::SSLeay::RSA_generate_key(512, 0x10001, \&cb_data, $userdata);
    }, 'RSA_generate_key with valid callback and userdata');

    cmp_ok( $called, '>', 0, 'callback has been called' );

    sub cb_data {
        my ($i, $n, $d) = @_;

        if ($called == 0) {
            is( wantarray(), undef, 'RSA_generate_key callback is executed in void context' );

            ok( defined $i, 'first argument is defined' );
            ok( defined $n, 'second argument is defined' );
            is( $d, $userdata, 'third argument is the userdata we passed in' );
        }

        $called++;
    }
}