File: 10-rsa-keys.t

package info (click to toggle)
libcrypt-openssl-pkcs10-perl 0.35-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792 kB
  • sloc: perl: 123; makefile: 3
file content (75 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download
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
74
75
use strict;
use warnings;

use Test::More tests => 27;
use Test::Lib;
use Test::Crypt::OpenSSL::PKCS10;

BEGIN { use_ok('Crypt::OpenSSL::PKCS10') };

my @hash = qw/SHA256/;
my @keysize = qw/512 1024 2048 3172 4096/;

#diag("Only hash passed should default to 1024"); 
foreach my $hash (@hash) {
    my $keysize = 1024;
    my $req = Crypt::OpenSSL::PKCS10->new({type => 'rsa', hash => $hash});
    my $output = get_openssl_output($req->get_pem_req());
    my $hash_re = lc($hash) . "WithRSAEncryption";
    like($output, qr/$hash_re/, "Digest $hash matches");
    my $keysize_re = "$keysize bit";
    like($output, qr/$keysize_re/m, "Public Keysize $keysize_re matches");
}

#diag("keysize and hash passed"); 
foreach my $hash (@hash) {
    foreach my $keysize (@keysize) {
        my $req = Crypt::OpenSSL::PKCS10->new($keysize, {type => 'rsa', hash => $hash});
        my $output = get_openssl_output($req->get_pem_req());
        my $hash_re = lc($hash) . "WithRSAEncryption";
        like($output, qr/$hash_re/, "Digest $hash matches");
        my $keysize_re = "$keysize bit";
        like($output, qr/$keysize_re/m, "Public Keysize $keysize_re matches");
    }
}

#diag("keysize only passed"); 
foreach my $keysize (@keysize) {
    my $hash = 'SHA256';
    my $req = Crypt::OpenSSL::PKCS10->new($keysize);
    my $output = get_openssl_output($req->get_pem_req());
    my $hash_re = lc($hash) . "WithRSAEncryption";
    like($output, qr/$hash_re/, "Digest $hash matches");
    my $keysize_re = "$keysize bit";
    like($output, qr/$keysize_re/m, "Public Keysize $keysize_re matches");
}

#diag("No arguements passed"); 
{
    my $hash = 'SHA256';
    my $keysize = 1024;
    my $req = Crypt::OpenSSL::PKCS10->new();
    my $output = get_openssl_output($req->get_pem_req());
    my $hash_re = lc($hash) . "WithRSAEncryption";
    like($output, qr/$hash_re/, "Digest $hash matches");
    my $keysize_re = "$keysize bit";
    like($output, qr/$keysize_re/m, "Public Keysize $keysize_re matches");
}

#diag("Too many arguements passed"); 
{
    eval {
        my $req = Crypt::OpenSSL::PKCS10->new(1024, {type => 'rsa', hash => 'SHA256'}, 'Too Many');
    };
    like ($@, qr/Maximum 2 optional arguements/, "Correctly errors on too many arguements");
}

#diag("keysize and hash passed in wrong order"); 
{
    eval {
        my $req = Crypt::OpenSSL::PKCS10->new({type => 'rsa', hash => 'SHA256'}, 1024);
    };
    like ($@, qr/Wrong order for arguements/, "Correctly errors on wrong order for arguements");
}

done_testing;