Skip to content

Commit 8c338db

Browse files
committed
use GitHub Actions instead of Travis CI
1 parent 86d851b commit 8c338db

File tree

5 files changed

+107
-3
lines changed

5 files changed

+107
-3
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
name: CI
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read # to fetch code (actions/checkout)
7+
8+
jobs:
9+
tests:
10+
name: Tests
11+
timeout-minutes: 10
12+
runs-on: ${{ matrix.os }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: ${{ matrix.php-version }}
20+
- name: Composer Install
21+
run: composer install --no-interaction --no-cache
22+
- name: Make Tests Compatiable With PHPUnit 9+
23+
if: contains(fromJSON('["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]'), matrix.php-version)
24+
run: php tests/make_compatible_with_phpunit9.php
25+
- name: PHPUnit
26+
run: vendor/bin/phpunit
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
os: [ubuntu-latest, windows-latest, macos-latest]
31+
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mcrypt_compat
22

3-
[![Build Status](https://travis-ci.org/phpseclib/mcrypt_compat.svg?branch=master)](https://app.travis-ci.com/github/phpseclib/mcrypt_compat)
3+
[![CI Status](https://github.com/phpseclib/mcrypt_compat/actions/workflows/ci.yml/badge.svg?branch=1.0&event=push "CI Status")](https://github.com/phpseclib/mcrypt_compat/actions/workflows/ci.yml?query=branch%3A1.0)
44

55
PHP 5.x-8.x polyfill for mcrypt extension.
66

lib/mcrypt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ function phpseclib_mcrypt_ecb($cipher, $key, $data, $mode, $iv = null)
11781178
*/
11791179
function phpseclib_mcrypt_encrypt($cipher, $key, $data, $mode, $iv = null)
11801180
{
1181-
return defined('PHPSECLIB_MCRYPT_TARGET_VERSION') && version_compare(PHPSECLIB_MCRYPT_TARGET_VERSION, '5.6.0', '>=') ?
1181+
return !defined('PHPSECLIB_MCRYPT_TARGET_VERSION') || version_compare(PHPSECLIB_MCRYPT_TARGET_VERSION, '5.6.0', '>=') ?
11821182
phpseclib_mcrypt_helper($cipher, $key, $data, $mode, $iv, 'encrypt') :
11831183
phpseclib_mcrypt_helper_old($cipher, $key, $data, $mode, $iv, 'encrypt');
11841184
}
@@ -1198,7 +1198,7 @@ function phpseclib_mcrypt_encrypt($cipher, $key, $data, $mode, $iv = null)
11981198
*/
11991199
function phpseclib_mcrypt_decrypt($cipher, $key, $data, $mode, $iv = null)
12001200
{
1201-
return defined('PHPSECLIB_MCRYPT_TARGET_VERSION') && version_compare(PHPSECLIB_MCRYPT_TARGET_VERSION, '5.6.0', '>=') ?
1201+
return !defined('PHPSECLIB_MCRYPT_TARGET_VERSION') || version_compare(PHPSECLIB_MCRYPT_TARGET_VERSION, '5.6.0', '>=') ?
12021202
phpseclib_mcrypt_helper($cipher, $key, $data, $mode, $iv, 'decrypt') :
12031203
phpseclib_mcrypt_helper_old($cipher, $key, $data, $mode, $iv, 'decrypt');
12041204
}

tests/MCryptCompatTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,53 @@ public function testMcryptGenericWithTwoParamsPHPPost71()
825825
phpseclib_mcrypt_generic_init($td, 'xxx');
826826
}
827827

828+
public function testOldMcryptNoIVWarning()
829+
{
830+
$key = 'key';
831+
$data = 'data';
832+
$iv = null;
833+
834+
$this->setExpectedException('PHPUnit_Framework_Error_Warning', 'mcrypt_encrypt(): Attempt to use an empty IV, which is NOT recommended');
835+
836+
phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt');
837+
}
838+
839+
public function testOldMcryptShortIVWarning()
840+
{
841+
$key = 'key';
842+
$data = 'data';
843+
$iv = 'iv';
844+
845+
$this->setExpectedException('PHPUnit_Framework_Error_Warning', 'mcrypt_encrypt(): The IV parameter must be as long as the blocksize');
846+
847+
phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt');
848+
}
849+
850+
public function testOldMcryptShortIV()
851+
{
852+
$key = 'key';
853+
$data = 'data';
854+
$iv = 'iv';
855+
856+
$result = @phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt');
857+
858+
$this->assertEquals('69c48f0bce2c81abd64bbab839080574', bin2hex($result));
859+
}
860+
861+
public function testOldMcryptNoIV()
862+
{
863+
$key = str_pad('key', 16, "\0");
864+
$data = 'data';
865+
$iv = null;
866+
867+
$result = @phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt');
868+
869+
// this yields the same result that testOldMcryptShortIV() yields. when the IV is invalid it's assumed to be all null bytes,
870+
// whilst a key that's not the right length is either null padded or truncated as appropriate
871+
872+
$this->assertEquals('69c48f0bce2c81abd64bbab839080574', bin2hex($result));
873+
}
874+
828875
public function providerForIVSizeChecks()
829876
{
830877
$tests = [
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/** @var iterable<SplFileInfo> $files */
4+
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__));
5+
foreach ($files as $file) {
6+
if ($file->getExtension() === 'php' && $file->getPathname() !== __FILE__) {
7+
$fileContents = file_get_contents($file->getPathname());
8+
if ($fileContents === false) {
9+
throw new \RuntimeException('file_get_contents() failed: ' . $file->getPathname());
10+
}
11+
$patternToReplacementMap = array(
12+
'~(n assertIsArray\([^,\)]*,)([^,\)]*\))~' => '$1 string $2: void',
13+
'~(n assertIsArray\([^,\)]*\))~' => '$1: void',
14+
'~(n assertIsString\([^\)]*\))~' => '$1: void',
15+
'~(n assertStringContainsString\([^\)]*\))~' => '$1: void'
16+
);
17+
$updatedFileContents = preg_replace(
18+
array_keys($patternToReplacementMap),
19+
array_values($patternToReplacementMap),
20+
$fileContents
21+
);
22+
if (file_put_contents($file->getPathname(), $updatedFileContents) === false) {
23+
throw new \RuntimeException('file_put_contents() failed: ' . $file->getPathname());
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)