1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

#[cfg(feature = "v23_7")]
#[cfg_attr(docsrs, doc(cfg(feature = "v23_7")))]
use crate::CertificateInfo;
use crate::{ffi, Backend};
use glib::translate::*;

/// Get all available signing certificate information
///
/// # Returns
///
/// all available signing certificate information
#[cfg(feature = "v23_7")]
#[cfg_attr(docsrs, doc(cfg(feature = "v23_7")))]
#[doc(alias = "poppler_get_available_signing_certificates")]
#[doc(alias = "get_available_signing_certificates")]
pub fn available_signing_certificates() -> Vec<CertificateInfo> {
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::poppler_get_available_signing_certificates())
    }
}

/// Returns the backend compiled into the poppler library.
///
/// # Returns
///
/// The backend used by poppler
#[doc(alias = "poppler_get_backend")]
#[doc(alias = "get_backend")]
pub fn backend() -> Backend {
    unsafe { from_glib(ffi::poppler_get_backend()) }
}

/// Get certificate by nick name
///
/// # Returns
///
/// a [`CertificateInfo`][crate::CertificateInfo] or [`None`] if not found
#[cfg(feature = "v23_7")]
#[cfg_attr(docsrs, doc(cfg(feature = "v23_7")))]
#[doc(alias = "poppler_get_certificate_info_by_id")]
#[doc(alias = "get_certificate_info_by_id")]
pub fn certificate_info_by_id(id: &str) -> Option<CertificateInfo> {
    unsafe { from_glib_full(ffi::poppler_get_certificate_info_by_id(id.to_glib_none().0)) }
}

/// Get NSS directory
///
/// # Returns
///
/// nss directroy.
#[cfg(feature = "v23_7")]
#[cfg_attr(docsrs, doc(cfg(feature = "v23_7")))]
#[doc(alias = "poppler_get_nss_dir")]
#[doc(alias = "get_nss_dir")]
pub fn nss_dir() -> Option<glib::GString> {
    unsafe { from_glib_full(ffi::poppler_get_nss_dir()) }
}

/// Returns the version of poppler in use. This result is not to be freed.
///
/// # Returns
///
/// the version of poppler.
#[doc(alias = "poppler_get_version")]
#[doc(alias = "get_version")]
pub fn version() -> Option<glib::GString> {
    unsafe { from_glib_none(ffi::poppler_get_version()) }
}

/// Converts a bytestring into a zero-terminated string suitable to
/// pass to [`Document::find_dest()`][crate::Document::find_dest()].
///
/// Note that the returned string has no defined encoding and is not
/// suitable for display to the user.
///
/// The returned data must be freed using `g_free()`.
/// ## `data`
/// the bytestring data
///
/// # Returns
///
/// the named dest
#[cfg(feature = "v0_73")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_73")))]
#[doc(alias = "poppler_named_dest_from_bytestring")]
pub fn named_dest_from_bytestring(data: &[u8]) -> Option<glib::GString> {
    let length = data.len() as _;
    unsafe {
        from_glib_full(ffi::poppler_named_dest_from_bytestring(
            data.to_glib_none().0,
            length,
        ))
    }
}

/// Converts a named dest string (e.g. from `PopplerDest.named_dest`) into a
/// bytestring, inverting the transformation of
/// [`named_dest_from_bytestring()`][crate::named_dest_from_bytestring()].
///
/// Note that the returned data is not zero terminated and may also
/// contains embedded NUL bytes.
///
/// If `name` is not a valid named dest string, returns [`None`].
///
/// The returned data must be freed using `g_free()`.
/// ## `name`
/// the named dest string
///
/// # Returns
///
/// a new bytestring,
///  or [`None`]
#[cfg(feature = "v0_73")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_73")))]
#[doc(alias = "poppler_named_dest_to_bytestring")]
pub fn named_dest_to_bytestring(name: &str) -> Vec<u8> {
    unsafe {
        let mut length = std::mem::MaybeUninit::uninit();
        let ret = FromGlibContainer::from_glib_full_num(
            ffi::poppler_named_dest_to_bytestring(name.to_glib_none().0, length.as_mut_ptr()),
            length.assume_init() as _,
        );
        ret
    }
}

/// Set NSS directory
#[cfg(feature = "v23_7")]
#[cfg_attr(docsrs, doc(cfg(feature = "v23_7")))]
#[doc(alias = "poppler_set_nss_dir")]
pub fn set_nss_dir(path: &str) {
    unsafe {
        ffi::poppler_set_nss_dir(path.to_glib_none().0);
    }
}

//#[cfg(feature = "v23_7")]
//#[cfg_attr(docsrs, doc(cfg(feature = "v23_7")))]
//#[doc(alias = "poppler_set_nss_password_callback")]
//pub fn set_nss_password_callback<P: FnMut() -> String>(func: P) {
//    unsafe { TODO: call ffi:poppler_set_nss_password_callback() }
//}