| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strictscip-perl cpan Crypt-Util 0.11 strict/; |
| 4 | use warningsscip-perl cpan Crypt-Util 0.11 warnings/; |
| 5 | |
| 6 | use Test::Morescip-perl cpan Crypt-Util 0.11 Test/More/; |
| 7 | use Test::Exceptionscip-perl cpan Crypt-Util 0.11 Test/Exception/; |
| 8 | |
| 9 | use Crypt::Utilscip-perl cpan Crypt-Util 0.11 Crypt/Util/; |
| 10 | |
| 11 | my ( $c, $fallback_cipher ); |
| 12 | |
| 13 | BEGIN { |
| 14 | $c = Crypt::Util->newscip-perl cpan Crypt-Util 0.11 Crypt/Util/new().; |
| 15 | |
| 16 | $fallback_cipher = eval { $c->fallback_cipherscip-perl cpan Crypt-Util 0.11 Crypt/Util/fallback_cipher(). }; |
| 17 | |
| 18 | planscip-perl cpan Crypt-Util 0.11 main/plan(). skip_all => "Couldn't load any cipher" if $@scip-perl cpan Crypt-Util 0.11 main/`$@`. =~ /^Couldn't load any cipher/; |
| 19 | |
| 20 | planscip-perl cpan Crypt-Util 0.11 main/plan(). 'no_plan'; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | my $key = $c->process_keyscip-perl cpan Crypt-Util 0.11 Crypt/Util/process_key().("foo"); |
| 25 | |
| 26 | okscip-perl cpan Crypt-Util 0.11 main/ok().( lengthscip-perl cpan Crypt-Util 0.11 main/length().($key), "key has some length" ); |
| 27 | |
| 28 | cmp_okscip-perl cpan Crypt-Util 0.11 main/cmp_ok().( $key, "ne", "foo", "it's a digest of some sort" ); |
| 29 | |
| 30 | isscip-perl cpan Crypt-Util 0.11 main/is().( $c->process_keyscip-perl cpan Crypt-Util 0.11 Crypt/Util/process_key().("foo", literal_key => 1), "foo", "literal key"); |
| 31 | |
| 32 | $c->default_use_literal_keyscip-perl cpan Crypt-Util 0.11 Crypt/Util/default_use_literal_key().(1); |
| 33 | |
| 34 | isscip-perl cpan Crypt-Util 0.11 main/is().( $c->process_keyscip-perl cpan Crypt-Util 0.11 Crypt/Util/process_key().("foo"), "foo", "literal key from defaults" ); |
| 35 | |
| 36 | $c->default_use_literal_keyscip-perl cpan Crypt-Util 0.11 Crypt/Util/default_use_literal_key().(0); |
| 37 | |
| 38 | foreach my $mode ( qw/stream block CBC CFB OFB Ctr/ ) { |
| 39 | SKIP: { |
| 40 | skipscip-perl cpan Crypt-Util 0.11 main/skip(). "$mode not installed ($@)", 1 unless eval { $c->cipher_objectscip-perl cpan Crypt-Util 0.11 Crypt/Util/cipher_object().( mode => $mode, key => "futz" ) }; |
| 41 | |
| 42 | my $ciphertext = $c->encrypt_stringscip-perl cpan Crypt-Util 0.11 Crypt/Util/encrypt_string().( |
| 43 | key => "moose", |
| 44 | string => "dancing", |
| 45 | mode => $mode, |
| 46 | ); |
| 47 | |
| 48 | isscip-perl cpan Crypt-Util 0.11 main/is().( |
| 49 | $c->decrypt_stringscip-perl cpan Crypt-Util 0.11 Crypt/Util/decrypt_string().( |
| 50 | key => "moose", |
| 51 | string => $ciphertext, |
| 52 | mode => $mode, |
| 53 | ), |
| 54 | "dancing", |
| 55 | "round trip using $mode", |
| 56 | ); |
| 57 | } |
| 58 | } |