-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge libpcsc-cpp and libpcsc-mock repositories
WE2-828 Signed-off-by: Raul Metsma <[email protected]>
- Loading branch information
Showing
33 changed files
with
4,141 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,26 +12,16 @@ jobs: | |
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
submodules: recursive | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install libraries | ||
run: | | ||
brew install web-eid/gtest/gtest | ||
ln -sf /usr/local/Cellar/[email protected]/1.1.1* /usr/local/opt/openssl | ||
- name: Create build directory | ||
run: mkdir build | ||
run: brew install web-eid/gtest/gtest | ||
|
||
- name: Configure CMake | ||
working-directory: ${{github.workspace}}/build | ||
run: cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} .. | ||
run: cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -B build -S . | ||
|
||
- name: Build | ||
working-directory: ${{github.workspace}}/build | ||
run: cmake --build . --config ${BUILD_TYPE} | ||
run: cmake --build build --config ${BUILD_TYPE} | ||
|
||
- name: Test | ||
working-directory: ${{github.workspace}}/build | ||
run: ctest -V -C ${BUILD_TYPE} | ||
run: ctest -V -C ${BUILD_TYPE} --test-dir build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
[submodule "lib/libpcsc-cpp"] | ||
path = lib/libpcsc-cpp | ||
url = ../libpcsc-cpp | ||
Submodule libpcsc-cpp
deleted from
fd79af
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(pcsc-cpp) | ||
|
||
# The libpcsc-cpp library itself. | ||
|
||
add_library(${PROJECT_NAME} | ||
STATIC | ||
include/${PROJECT_NAME}/${PROJECT_NAME}.hpp | ||
include/${PROJECT_NAME}/${PROJECT_NAME}-utils.hpp | ||
include/${PROJECT_NAME}/comp_winscard.hpp | ||
include/flag-set-cpp/flag_set.hpp | ||
include/magic_enum/magic_enum.hpp | ||
src/Context.hpp | ||
src/Reader.cpp | ||
src/SCardCall.hpp | ||
src/SmartCard.cpp | ||
src/listReaders.cpp | ||
src/utils.cpp | ||
) | ||
|
||
target_include_directories(${PROJECT_NAME} | ||
PUBLIC | ||
include | ||
) | ||
|
||
target_compile_features(${PROJECT_NAME} | ||
PUBLIC | ||
cxx_std_17 | ||
) | ||
|
||
target_compile_options(${PROJECT_NAME} PUBLIC | ||
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX> | ||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -pedantic -Werror> | ||
) | ||
|
||
target_compile_definitions(${PROJECT_NAME} PUBLIC | ||
$<$<CXX_COMPILER_ID:MSVC>:WIN32_LEAN_AND_MEAN;UNICODE;_CRT_SECURE_NO_WARNINGS> | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE | ||
$<$<CXX_COMPILER_ID:MSVC>:Ws2_32> | ||
) | ||
|
||
# PC/SC API dependencies. | ||
|
||
add_library(pcsc INTERFACE) | ||
if(MSVC) | ||
target_link_libraries(pcsc INTERFACE winscard) | ||
elseif(APPLE) | ||
target_link_libraries(pcsc INTERFACE "-framework PCSC") | ||
else() | ||
find_package(PkgConfig REQUIRED) | ||
pkg_check_modules(PCSC libpcsclite REQUIRED IMPORTED_TARGET) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${PCSC_INCLUDE_DIRS}) | ||
target_link_libraries(pcsc INTERFACE PkgConfig::PCSC) | ||
endif() | ||
|
||
# Common testing options. | ||
|
||
enable_testing() | ||
|
||
find_package(GTest REQUIRED) | ||
|
||
# Mock tests that use libpcsc-mock to mock PC/SC API calls. | ||
|
||
set(MOCK_TEST_EXE lib${PROJECT_NAME}-test-mock) | ||
|
||
add_subdirectory(tests/lib/libpcsc-mock) | ||
|
||
add_executable(${MOCK_TEST_EXE} | ||
tests/mock/test-select-card-reader-and-card.cpp | ||
tests/mock/test-connect-to-card-transmit-apdus.cpp | ||
) | ||
|
||
target_link_libraries(${MOCK_TEST_EXE} | ||
${PROJECT_NAME} | ||
pcsc-mock | ||
GTest::Main | ||
) | ||
|
||
add_test(${MOCK_TEST_EXE} ${MOCK_TEST_EXE}) | ||
|
||
# Integration tests that use the real operating system PC/SC service. | ||
|
||
set(INTEGRATION_TEST_EXE lib${PROJECT_NAME}-test-integration) | ||
|
||
add_executable(${INTEGRATION_TEST_EXE} | ||
tests/integration/test-${PROJECT_NAME}.cpp | ||
) | ||
|
||
target_link_libraries(${INTEGRATION_TEST_EXE} | ||
${PROJECT_NAME} | ||
pcsc | ||
GTest::Main | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020-2023 Estonian Information System Authority | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# libpcsc-cpp | ||
|
||
![European Regional Development Fund](https://github.com/open-eid/DigiDoc4-Client/blob/master/client/images/EL_Regionaalarengu_Fond.png) | ||
|
||
C++ library for accessing smart cards using the PC/SC API. | ||
|
||
## Usage | ||
|
||
Example how to list available readers, connect to the smart card in first | ||
reader and transmit an APDU: | ||
|
||
auto readers = listReaders(); | ||
auto card = readers[0].connectToCard(); | ||
auto command = CommandApdu::fromBytes({0x2, 0x1, 0x3, 0x4}); | ||
|
||
auto transactionGuard = card->beginTransaction(); | ||
auto response = card->transmit(command); | ||
|
||
See more examples in [tests](tests). | ||
|
||
## Building | ||
|
||
In Ubuntu: | ||
|
||
apt install build-essential pkg-config cmake libgtest-dev valgrind libpcsclite-dev | ||
sudo bash -c 'cd /usr/src/googletest && cmake . && cmake --build . --target install' | ||
|
||
cd build | ||
cmake .. # optionally with -DCMAKE_BUILD_TYPE=Debug | ||
cmake --build . # optionally with VERBOSE=1 | ||
|
||
## Testing | ||
|
||
Build as described above, then, inside the `build` directory, run: | ||
|
||
ctest # or 'valgrind --leak-check=full ctest' | ||
|
||
`ctest` runs tests that use the _libscard-mock_ library to mock PC/SC API calls. | ||
|
||
There are also integration tests that use the real operating system PC/SC | ||
service, run them inside `build` directory with: | ||
|
||
./libpcsc-cpp-test-integration | ||
|
||
## Development guidelines | ||
|
||
- Format code with `scripts/clang-format.sh` before committing | ||
- See [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
TODO: | ||
|
||
- coding conventions - Qt coding style and conventions | ||
- gtest and winscard-mock usage | ||
- API | ||
- architecture | ||
- technical design | ||
- describe PIMPL (we don't want to leak `winscard.h` to clients) |
Oops, something went wrong.