Skip to content

Commit 16a04d6

Browse files
authored
Fix C# build (#663)
IB-8343 Signed-off-by: Raul Metsma <[email protected]>
1 parent dd315aa commit 16a04d6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

libdigidocpp.i

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ extern "C"
7575
[global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="ByteVector_to")]
7676
public static extern global::System.IntPtr ByteVector_to(
7777
[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]byte[] data, int size);
78+
public static byte[] To_ByteArray(global::System.IntPtr cPtr) {
79+
byte[] result = new byte[$modulePINVOKE.ByteVector_size(cPtr)];
80+
global::System.Runtime.InteropServices.Marshal.Copy($modulePINVOKE.ByteVector_data(cPtr), result, 0, result.Length);
81+
$modulePINVOKE.ByteVector_free(cPtr);
82+
return result;
83+
}
7884
%}
7985

8086
#ifdef SWIGJAVA
@@ -116,21 +122,15 @@ static std::vector<unsigned char>* SWIG_JavaArrayToVectorUnsignedChar(JNIEnv *je
116122
%typemap(cstype) std::vector<unsigned char> "byte[]"
117123
%typemap(cstype) digidoc::X509Cert "System.Security.Cryptography.X509Certificates.X509Certificate2"
118124
%typemap(csin, pre= " global::System.IntPtr cPtr$csinput = digidocPINVOKE.ByteVector_to($csinput, $csinput.Length);
119-
var handleRef$csinput = new global::System.Runtime.InteropServices.HandleRef(this, cPtr$csinput);"
125+
var handleRef$csinput = new global::System.Runtime.InteropServices.HandleRef($csinput, cPtr$csinput);"
120126
) std::vector<unsigned char> "handleRef$csinput"
121127
%typemap(csout, excode=SWIGEXCODE) std::vector<unsigned char> {
122128
global::System.IntPtr cPtr = $imcall;$excode
123-
byte[] result = new byte[$modulePINVOKE.ByteVector_size(cPtr)];
124-
global::System.Runtime.InteropServices.Marshal.Copy($modulePINVOKE.ByteVector_data(cPtr), result, 0, result.Length);
125-
$modulePINVOKE.ByteVector_free(cPtr);
126-
return result;
129+
return $modulePINVOKE.To_ByteArray(cPtr);
127130
}
128131
%typemap(csout, excode=SWIGEXCODE) digidoc::X509Cert {
129132
global::System.IntPtr cPtr = $imcall;$excode
130-
byte[] der = new byte[$modulePINVOKE.ByteVector_size(cPtr)];
131-
global::System.Runtime.InteropServices.Marshal.Copy($modulePINVOKE.ByteVector_data(cPtr), der, 0, der.Length);
132-
$modulePINVOKE.ByteVector_free(cPtr);
133-
return new System.Security.Cryptography.X509Certificates.X509Certificate2(der);
133+
return new System.Security.Cryptography.X509Certificates.X509Certificate2($modulePINVOKE.To_ByteArray(cPtr));
134134
}
135135
%typemap(out) std::vector<unsigned char> %{ $result = new std::vector<unsigned char>(std::move($1)); %}
136136
%typemap(out) digidoc::X509Cert %{ $result = new std::vector<unsigned char>($1); %}

0 commit comments

Comments
 (0)