Skip to content

Commit

Permalink
Merge pull request #9 from rnpgp/antonsviridenko-2-ci-tests
Browse files Browse the repository at this point in the history
Run CI tests using GitHub Actions.
  • Loading branch information
antonsviridenko authored Apr 4, 2023
2 parents 34e865d + 4551c1b commit 86cbffd
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 8 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright (c) 2022-2023 Ribose Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

name: test

on:
pull_request:
push:
branches: [ main ]
tags: [ v* ]
repository_dispatch:
types: [ run-php-rnp]
workflow_dispatch:

concurrency:
group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
cancel-in-progress: true

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Setup test matrix
id: matrix
run: |
if [ "${{ github.event.client_payload }}" != "" ]; then
echo "matrix=[ '${{ github.event.client_payload.tag }}' ]" >> $GITHUB_OUTPUT;
else
echo "matrix=[ 'v0.16.2', 'master' ]" >> $GITHUB_OUTPUT;
fi
build-and-test:
needs: prepare
strategy:
fail-fast: false
matrix:
php: [ '8.0', '8.1', '8.2' ]
rnp: ${{ fromJson(needs.prepare.outputs.matrix) }}

runs-on: ubuntu-latest
steps:
- name: Install packages
# Already installed on GHA: build-essential libbz2-dev zlib1g-dev
run: sudo apt-get install cmake libbotan-2-dev libjson-c-dev

- name: Checkout rnp
uses: actions/checkout@v3
with:
repository: rnpgp/rnp
path: rnp
submodules: true
ref: ${{ matrix.rnp }}

- name: Configure rnp
run: cmake -B rnp/build -DBUILD_TESTING=OFF -DENABLE_DOC=OFF -DBUILD_SHARED_LIBS=ON rnp

- name: Build rnp
run: cmake --build rnp/build

- name: Install rnp
run: sudo cmake --install rnp/build

- name: php-rnp
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
tools: phpize
extensions: json

- name: Build
run: |
phpize
./configure
make
sudo make install
- name: Run tests
run: |
echo "n" | make test
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.libs/
*.cache/
build/
modules/

config.h
config.h.in
config.log
config.nice
config.status
configure
configure.ac
Makefile
Makefile.fragments
Makefile.objects
libtool

rnp.dep
rnp.la
rnp.lo

run-tests.php
14 changes: 14 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
= PHP RNP bindings

image:https://github.com/rnpgp/php-rnp/actions/workflows/test.yml/badge.svg["Build Status", link="https://github.com/rnpgp/php-rnp/actions/workflows/test.yml"]

This extension provides php bindings to the
https://github.com/rnpgp/rnp[librnp OpenPGP library].

== Requirements

This extension currently requires https://github.com/rnpgp/rnp[librnp] 0.16.2 or newer.

== Documentation

Documentation for this extension is available in https://www.php.net/manual/en/book.rnp.php[PHP Manual].
23 changes: 20 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2022-10-25</date>
<date>2023-04-04</date>
<version>
<release>0.1.1</release>
<release>0.2.0</release>
<api>0.1</api>
</version>
<stability>
Expand All @@ -27,7 +27,8 @@
</stability>
<license uri="https://github.com/rnpgp/php-rnp/blob/main/LICENSE">BSD 2-Clause License</license>
<notes><![CDATA[
* Initial release
* Setting symmetric cyphers for password-encrypted messages according to changes in RNP
* Display version info
]]></notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -76,6 +77,22 @@
<providesextension>rnp</providesextension>
<extsrcrelease />
<changelog>
<release>
<version>
<release>0.2.0</release>
<api>0.1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<date>2023-04-04</date>
<license uri="https://github.com/rnpgp/php-rnp/blob/main/LICENSE">BSD 2-Clause License</license>
<notes><![CDATA[
* Setting symmetric cyphers for password-encrypted messages according to changes in RNP
* Display version info
]]></notes>
</release>
<release>
<version>
<release>0.1.1</release>
Expand Down
2 changes: 1 addition & 1 deletion php_rnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static inline php_rnp_ffi_t *rnp_ffi_t_from_obj(zend_object *obj)

PHP_RNP_API extern zend_class_entry *rnp_ffi_t_ce;

# define PHP_RNP_VERSION "0.1.1"
# define PHP_RNP_VERSION "0.2.0"

# if defined(ZTS) && defined(COMPILE_DL_RNP)
ZEND_TSRMLS_CACHE_EXTERN()
Expand Down
13 changes: 9 additions & 4 deletions rnp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ PHP_FUNCTION(rnp_op_encrypt)
if (ZEND_NUM_ARGS() > 3 && options && Z_TYPE_P(options) == IS_ARRAY) {
zval *opt;
const char *compression_alg = NULL;
const char *cipher = NULL;
int compression_level = 0;

if ((opt = zend_hash_str_find(Z_ARRVAL_P(options), "compression_alg", sizeof("compression_alg") - 1)) != NULL &&
Expand Down Expand Up @@ -1355,17 +1356,21 @@ PHP_FUNCTION(rnp_op_encrypt)
}
}

if ((opt = zend_hash_str_find(Z_ARRVAL_P(options), "cipher", sizeof("cipher") - 1)) != NULL &&
Z_TYPE_P(opt) == IS_STRING) {
cipher = Z_STRVAL_P(opt);
}

if ((opt = zend_hash_str_find(Z_ARRVAL_P(options), "password", sizeof("password") - 1)) != NULL &&
Z_TYPE_P(opt) == IS_STRING) {
if ((ret = rnp_op_encrypt_add_password(encrypt, Z_STRVAL_P(opt), NULL, 0, NULL))) {
if ((ret = rnp_op_encrypt_add_password(encrypt, Z_STRVAL_P(opt), NULL, 0, cipher))) {
goto done;
}
password = Z_STRVAL_P(opt);
}

if ((opt = zend_hash_str_find(Z_ARRVAL_P(options), "cipher", sizeof("cipher") - 1)) != NULL &&
Z_TYPE_P(opt) == IS_STRING) {
if ((ret = rnp_op_encrypt_set_cipher(encrypt, Z_STRVAL_P(opt)))) {
if (cipher != NULL) {
if ((ret = rnp_op_encrypt_set_cipher(encrypt, cipher))) {
goto done;
}
}
Expand Down

0 comments on commit 86cbffd

Please sign in to comment.