Skip to content

Commit

Permalink
Build C# bindings on other platforms
Browse files Browse the repository at this point in the history
IB-7574

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma committed Nov 4, 2022
1 parent 0bc9978 commit 77381d3
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
curl https://installer.id.ee/media/install-scripts/C6C83D68.pub | gpg --dearmor | tee /etc/apt/trusted.gpg.d/ria-repository.gpg > /dev/null
echo "deb https://installer.id.ee/media/ubuntu/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ria-repository.list
- name: Install dependencies
run: apt update -qq && apt install --no-install-recommends -y lsb-release dh-make fakeroot build-essential devscripts cdbs cmake vim-common xsdcxx libxml-security-c-dev zlib1g-dev doxygen swig openjdk-8-jdk-headless libpython3-dev python3-distutils libboost-test-dev lintian
run: apt update -qq && apt install --no-install-recommends -y lsb-release fakeroot build-essential devscripts cdbs cmake vim-common xsdcxx libxml-security-c-dev zlib1g-dev doxygen swig openjdk-8-jdk-headless libpython3-dev python3-distutils libboost-test-dev lintian
- name: Setup changelog
run: |
export VERSION=$(grep project CMakeLists.txt | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
Expand Down
37 changes: 35 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Build-Depends:
cmake,
libxml-security-c-dev,
xsdcxx (>= 4.0) | xsd (>= 4.0),
vim-common,
xxd,
doxygen,
swig,
libpython3-dev,
Expand Down Expand Up @@ -67,13 +67,46 @@ Architecture: any
Section: libdevel
Depends:
libdigidocpp1 (= ${binary:Version}),
python3,
${misc:Depends},
${shlibs:Depends}
Description: DigiDoc digital signature library development files
This package contains files necessary for developing applications with the
DigiDoc digital signature library.

Package: libdigidocpp-csharp
Architecture: any
Section: libdevel
Depends:
libdigidocpp1 (= ${binary:Version}),
${misc:Depends},
${shlibs:Depends}
Description: DigiDoc digital signature C# bindings
This package contains files necessary for developing applications with the
DigiDoc digital signature library using C# bindings.

Package: libdigidocpp-java
Architecture: any
Section: libdevel
Depends:
libdigidocpp1 (= ${binary:Version}),
${misc:Depends},
${shlibs:Depends}
Description: DigiDoc digital signature java bindings
This package contains files necessary for developing applications with the
DigiDoc digital signature library using java bindings.

Package: libdigidocpp-python
Architecture: any
Section: libdevel
Depends:
libdigidocpp1 (= ${binary:Version}),
python3,
${misc:Depends},
${shlibs:Depends}
Description: DigiDoc digital signature python bindings
This package contains files necessary for developing applications with the
DigiDoc digital signature library using python bindings.

Package: libdigidocpp-doc
Architecture: all
Section: doc
Expand Down
2 changes: 2 additions & 0 deletions debian/libdigidocpp-csharp.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/include/digidocpp_csharp/
usr/lib/*/libdigidoc_csharp.so
1 change: 1 addition & 0 deletions debian/libdigidocpp-csharp.lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libdigidocpp-csharp: sharedobject-in-library-directory-missing-soname
File renamed without changes.
5 changes: 2 additions & 3 deletions debian/libdigidocpp-dev.install
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
usr/include
usr/lib/*/lib*.so
usr/include/digidocpp/
usr/lib/*/libdigidocpp.so
usr/lib/*/pkgconfig
usr/lib/python*/dist-packages
1 change: 0 additions & 1 deletion debian/libdigidocpp-dev.lintian-overrides

This file was deleted.

2 changes: 2 additions & 0 deletions debian/libdigidocpp-java.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/include/ee/ria/libdigidocpp/
usr/lib/*/libdigidoc_java.so
1 change: 1 addition & 0 deletions debian/libdigidocpp-java.lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libdigidocpp-java: sharedobject-in-library-directory-missing-soname
1 change: 1 addition & 0 deletions debian/libdigidocpp-java.triggers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
activate-noawait ldconfig
1 change: 1 addition & 0 deletions debian/libdigidocpp-python.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/python3/dist-packages/
2 changes: 1 addition & 1 deletion debian/libdigidocpp1.install
Original file line number Diff line number Diff line change
@@ -1 +1 @@
usr/lib/*/lib*.so.*
usr/lib/*/libdigidocpp.so.*
4 changes: 4 additions & 0 deletions examples/DigiDocCSharp/DigiDocCSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<DefineConstants>_WINDOWS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
71 changes: 49 additions & 22 deletions examples/DigiDocCSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,47 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using digidoc;

namespace DigiDocCSharp
{
class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Missing document parameter");
help();
Help();
return;
}

switch (args[0])
{
case "add": add(args); return;
case "extract": extract(Convert.ToInt32(args[1]), args[2]); return;
case "sign": sign(args); return;
case "websign": websign(args); return;
case "verify": verify(args[1]); return;
case "version": version(); return;
case "add": Add(args); return;
case "extract": Extract(Convert.ToInt32(args[1]), args[2]); return;
case "sign": Sign(args); return;
case "websign": Websign(args); return;
case "verify": Verify(args[1]); return;
case "version": Version(); return;
case "help":
default: help(); return;
default: Help(); return;
}
}

static void add(string[] args)
private static void Add(string[] args)
{
digidoc.digidoc.initialize();
try
{
Console.WriteLine("Creating file: " + args[args.Length - 1]);
Container b = Container.create(args[args.Length - 1]);
for (int i = 1; i < args.Length - 1; ++i)
{
b.addDataFile(args[i], "application/octet-stream");
}
b.save();
}
catch (Exception e)
Expand All @@ -51,7 +54,7 @@ static void add(string[] args)
digidoc.digidoc.terminate();
}

static void extract(int index, string file)
private static void Extract(int index, string file)
{
digidoc.digidoc.initialize();
try
Expand All @@ -78,7 +81,7 @@ static void extract(int index, string file)
digidoc.digidoc.terminate();
}

static void help()
private static void Help()
{
Console.WriteLine("DigiDocCSharp command [params]");
Console.WriteLine("Command:");
Expand All @@ -91,6 +94,9 @@ static void help()
Console.WriteLine(" datafile1 datafile2 ...");
Console.WriteLine(" file");
Console.WriteLine(" sign\t\tSigns file");
#if !_WINDOWS
Console.WriteLine(" 12345");
#endif
Console.WriteLine(" datafile1 datafile2 ...");
Console.WriteLine(" file");
Console.WriteLine(" websign\t\tSigns file");
Expand All @@ -99,20 +105,34 @@ static void help()
Console.WriteLine(" file");
Console.WriteLine(" verify\t\tVerifies document signature and shows info");
Console.WriteLine(" file");
version();
Version();
}

static void sign(string[] args)
private static void Sign(string[] args)
{
digidoc.digidoc.initialize();
try
{
Console.WriteLine("Creating file: " + args[args.Length-1]);
Console.WriteLine("Creating file: " + args[args.Length - 1]);
Container b = Container.create(args[args.Length - 1]);
#if _WINDOWS
for (int i = 1; i < args.Length - 1; ++i)
#else
for (int i = 2; i < args.Length - 1; ++i)
#endif
{
b.addDataFile(args[i], "application/octet-stream");
}
#if _WINDOWS
using (WinSigner signer = new WinSigner())
{
#else
using (PKCS11Signer signer = new PKCS11Signer())
{
signer.setPin(args[1]);
#endif
b.sign(signer);
}
b.save();
}
catch (Exception e)
Expand All @@ -122,15 +142,17 @@ static void sign(string[] args)
digidoc.digidoc.terminate();
}

static void websign(string[] args)
private static void Websign(string[] args)
{
digidoc.digidoc.initialize();
try
{
Console.WriteLine("Creating file: " + args[args.Length - 1]);
Container b = Container.create(args[args.Length - 1]);
for (int i = 1; i < args.Length - 2; ++i)
{
b.addDataFile(args[i], "application/octet-stream");
}

X509Certificate cert = new X509Certificate();
cert.Import(args[args.Length - 2]);
Expand All @@ -142,7 +164,7 @@ static void websign(string[] args)
byte[] inputBuffer = new byte[1024];
Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
String hex = Console.ReadLine();
string hex = Console.ReadLine();

byte[] signature = Enumerable.Range(0, hex.Length / 2).Select(x => Convert.ToByte(hex.Substring(x * 2, 2), 16)).ToArray();
c.setSignatureValue(signature);
Expand All @@ -156,7 +178,7 @@ static void websign(string[] args)
digidoc.digidoc.terminate();
}

static void verify(string file)
private static void Verify(string file)
{
digidoc.digidoc.initialize();
try
Expand All @@ -166,7 +188,9 @@ static void verify(string file)

Console.WriteLine("Files:");
foreach (DataFile d in b.dataFiles())
{
Console.WriteLine(" {0} - {1}", d.fileName(), d.mediaType());
}
Console.WriteLine();

Console.WriteLine("Signatures:");
Expand All @@ -175,8 +199,10 @@ static void verify(string file)
Console.WriteLine("Address: {0} {1} {2} {3}", s.city(), s.countryName(), s.stateOrProvince(), s.postalCode());

Console.Write("Role:");
foreach (String role in s.signerRoles())
foreach (string role in s.signerRoles())
{
Console.Write(" " + role);
}
Console.WriteLine();

Console.WriteLine("Time: " + s.trustedSigningTime());
Expand All @@ -194,9 +220,10 @@ static void verify(string file)
digidoc.digidoc.terminate();
}

static void version()
private static void Version()
{
Console.WriteLine("DigiDocCSharp 0.3 libdigidocpp " + digidoc.digidoc.version());
Console.WriteLine("DigiDocCSharp " + Assembly.GetExecutingAssembly().GetName().Version +
" libdigidocpp " + digidoc.digidoc.version());
}
}
}
5 changes: 2 additions & 3 deletions examples/DigiDocCSharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -32,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")]
3 changes: 1 addition & 2 deletions libdigidocpp.i
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ namespace std {
%include "crypto/Signer.h"
%include "crypto/PKCS12Signer.h"
%include "crypto/PKCS11Signer.h"
#ifdef SWIGCSHARP
// FIXME: figure out how to expose WinSigner on windows only. SWIG currently does not support this
#ifdef SWIGWIN
%include "crypto/WinSigner.h"
#endif
%include "libdigidocpp.i.h"
Expand Down
23 changes: 16 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ if(SWIG_FOUND)
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/java)
swig_add_library(digidoc_java TYPE SHARED LANGUAGE java SOURCES ../libdigidocpp.i)
target_include_directories(digidoc_java PRIVATE ${JAVA_INCLUDE_PATH} $<$<BOOL:${JAVA_INCLUDE_PATH2}>:${JAVA_INCLUDE_PATH2}>)
swig_link_libraries(digidoc_java digidocpp digidocpp_util)
target_link_libraries(digidoc_java digidocpp digidocpp_util)
set_property(TARGET digidoc_java PROPERTY SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>)
if(APPLE)
install(TARGETS digidoc_java DESTINATION /Library/Java/Extensions)
else()
Expand All @@ -281,6 +282,7 @@ if(SWIG_FOUND)
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
swig_add_library(digidoc_python TYPE SHARED LANGUAGE python SOURCES ../libdigidocpp.i)
target_link_libraries(${SWIG_MODULE_digidoc_python_REAL_NAME} digidocpp digidocpp_util PythonModule)
set_property(TARGET ${SWIG_MODULE_digidoc_python_REAL_NAME} PROPERTY SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>)
#configure_file(setup.py.cmake setup.py)
#install(CODE "execute_process(COMMAND python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)")
if(NOT Python3_SITELIB)
Expand All @@ -297,14 +299,21 @@ if(SWIG_FOUND)
install(TARGETS ${SWIG_MODULE_digidoc_python_REAL_NAME} DESTINATION ${Python3_SITELIB})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/digidoc.py DESTINATION ${Python3_SITELIB})
endif()

set(CMAKE_SWIG_FLAGS -dllimport digidoc_csharp -namespace digidoc)
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/csharp)
swig_add_library(digidoc_csharp TYPE SHARED LANGUAGE csharp SOURCES ../libdigidocpp.i)
target_link_libraries(digidoc_csharp digidocpp digidocpp_util)
set_target_properties(digidoc_csharp PROPERTIES
SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>
INSTALL_RPATH $<$<PLATFORM_ID:Darwin>:/Library/Frameworks>
)
install(TARGETS digidoc_csharp DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/csharp/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/digidocpp_csharp FILES_MATCHING PATTERN "*.cs")
if(WIN32)
set(CMAKE_SWIG_FLAGS -dllimport digidoc_csharp -namespace digidoc)
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/csharp)
swig_add_library(digidoc_csharp TYPE SHARED LANGUAGE csharp SOURCES ../libdigidocpp.i)
swig_link_libraries(digidoc_csharp digidocpp digidocpp_util)
install(TARGETS digidoc_csharp DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/csharp/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/digidocpp_csharp FILES_MATCHING PATTERN "*.cs")
install(FILES $<TARGET_PDB_FILE:digidoc_csharp> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
else()
set_target_properties(digidoc_csharp PROPERTIES PREFIX lib)
endif()
endif()

Expand Down

0 comments on commit 77381d3

Please sign in to comment.