Skip to content

Commit

Permalink
gio: manually generate get_channel_binding_data
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Oct 10, 2020
1 parent fddbeed commit ad71d74
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
10 changes: 9 additions & 1 deletion Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ generate = [
"Gio.TlsCertificateRequestFlags",
"Gio.TlsChannelBindingType",
"Gio.TlsClientConnection",
"Gio.TlsConnection",
"Gio.TlsDatabase",
"Gio.TlsDatabaseLookupFlags",
"Gio.TlsDatabaseVerifyFlags",
Expand Down Expand Up @@ -1017,6 +1016,15 @@ status = "generate"
name = "source_object"
nullable = true

[[object]]
name = "Gio.TlsConnection"
status = "generate"
manual_traits = ["TlsConnectionExtManual"]
[[object.function]]
name = "get_channel_binding_data"
# Gir confuses the mutability of the data
ignore = true

[[object]]
name = "Gio.TlsPassword"
status = "generate"
Expand Down
30 changes: 0 additions & 30 deletions src/auto/tls_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use Cancellable;
use IOStream;
use TlsCertificate;
use TlsCertificateFlags;
#[cfg(any(feature = "v2_66", feature = "dox"))]
use TlsChannelBindingType;
use TlsDatabase;
use TlsInteraction;
use TlsRehandshakeMode;
Expand All @@ -49,12 +47,6 @@ pub trait TlsConnectionExt: 'static {

fn get_certificate(&self) -> Option<TlsCertificate>;

#[cfg(any(feature = "v2_66", feature = "dox"))]
fn get_channel_binding_data(
&self,
type_: TlsChannelBindingType,
) -> Result<glib::ByteArray, glib::Error>;

fn get_database(&self) -> Option<TlsDatabase>;

fn get_interaction(&self) -> Option<TlsInteraction>;
Expand Down Expand Up @@ -174,28 +166,6 @@ impl<O: IsA<TlsConnection>> TlsConnectionExt for O {
}
}

#[cfg(any(feature = "v2_66", feature = "dox"))]
fn get_channel_binding_data(
&self,
type_: TlsChannelBindingType,
) -> Result<glib::ByteArray, glib::Error> {
unsafe {
let mut data = ptr::null_mut();
let mut error = ptr::null_mut();
let _ = gio_sys::g_tls_connection_get_channel_binding_data(
self.as_ref().to_glib_none().0,
type_.to_glib(),
&mut data,
&mut error,
);
if error.is_null() {
Ok(from_glib_none(data))
} else {
Err(from_glib_full(error))
}
}
}

fn get_database(&self) -> Option<TlsDatabase> {
unsafe {
from_glib_none(gio_sys::g_tls_connection_get_database(
Expand Down
2 changes: 1 addition & 1 deletion src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ ad40c01)
from gir-files (https://github.com/gtk-rs/gir-files @ 4ad8962)
from gir-files (https://github.com/gtk-rs/gir-files @ 8a626fd)
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ mod read_input_stream;
pub use read_input_stream::ReadInputStream;
mod write_output_stream;
pub use write_output_stream::WriteOutputStream;
mod tls_connection;
pub use tls_connection::TlsConnectionManualExt;
40 changes: 40 additions & 0 deletions src/tls_connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#[cfg(any(feature = "v2_66", feature = "dox"))]
use auto::TlsChannelBindingType;
use auto::TlsConnection;
#[cfg(any(feature = "v2_66", feature = "dox"))]
use glib::translate::*;
use glib::IsA;
#[cfg(any(feature = "v2_66", feature = "dox"))]
use std::ptr;

pub trait TlsConnectionManualExt {
#[cfg(any(feature = "v2_66", feature = "dox"))]
fn get_channel_binding_data(
&self,
type_: TlsChannelBindingType,
) -> Result<glib::ByteArray, glib::Error>;
}

impl<O: IsA<TlsConnection>> TlsConnectionManualExt for O {
#[cfg(any(feature = "v2_66", feature = "dox"))]
fn get_channel_binding_data(
&self,
type_: TlsChannelBindingType,
) -> Result<glib::ByteArray, glib::Error> {
unsafe {
let data = ptr::null_mut();
let mut error = ptr::null_mut();
let _ = gio_sys::g_tls_connection_get_channel_binding_data(
self.to_glib_none().0,
type_.to_glib(),
data,
&mut error,
);
if error.is_null() {
Ok(from_glib_none(data))
} else {
Err(from_glib_full(error))
}
}
}
}

0 comments on commit ad71d74

Please sign in to comment.