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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ b215ee8)
// DO NOT EDIT

use CertificateList;
use DigestAlgo;
use SignatureList;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// An object containing the results from decrypting an encrypted stream.
    ///
    /// # Implements
    ///
    /// [`DecryptResultExt`](trait.DecryptResultExt.html)
    pub struct DecryptResult(Object<ffi::GMimeDecryptResult, ffi::GMimeDecryptResultClass>);

    match fn {
        get_type => || ffi::g_mime_decrypt_result_get_type(),
    }
}

impl DecryptResult {
    /// Creates a new `DecryptResult` object.
    ///
    /// # Returns
    ///
    /// a new `DecryptResult` object.
    pub fn new() -> DecryptResult {
        unsafe {
            from_glib_full(ffi::g_mime_decrypt_result_new())
        }
    }
}

impl Default for DecryptResult {
    fn default() -> Self {
        Self::new()
    }
}

/// Trait containing all `DecryptResult` methods.
///
/// # Implementors
///
/// [`DecryptResult`](struct.DecryptResult.html)
pub trait DecryptResultExt {
    //fn get_cipher(&self) -> /*Ignored*/CipherAlgo;

    /// Get the mdc digest algorithm used.
    ///
    /// # Returns
    ///
    /// the mdc digest algorithm used.
    fn get_mdc(&self) -> DigestAlgo;

    /// Gets the list of certificates that the stream had been encrypted to.
    ///
    /// # Returns
    ///
    /// a `CertificateList`.
    fn get_recipients(&self) -> Option<CertificateList>;

    /// Get the session key used for this decryption.
    ///
    /// # Returns
    ///
    /// the session key digest algorithm used, or `None` if no
    /// session key was requested or found.
    fn get_session_key(&self) -> Option<String>;

    /// Gets a list of signatures if the encrypted stream had also been signed.
    ///
    /// # Returns
    ///
    /// a `SignatureList` or `None` if the
    /// stream was not signed.
    fn get_signatures(&self) -> Option<SignatureList>;

    //fn set_cipher(&self, cipher: /*Ignored*/CipherAlgo);

    /// Set the mdc digest algorithm used.
    /// ## `mdc`
    /// a `DigestAlgo`
    fn set_mdc(&self, mdc: DigestAlgo);

    /// Sets the list of certificates that the stream had been encrypted to.
    /// ## `recipients`
    /// A `CertificateList`
    fn set_recipients(&self, recipients: &CertificateList);

    /// Set the session key to be returned by this decryption result.
    /// ## `session_key`
    /// a string representing the session key or `None` to unset the key
    fn set_session_key<'a, P: Into<Option<&'a str>>>(&self, session_key: P);

    /// Sets the list of signatures.
    /// ## `signatures`
    /// A `SignatureList`
    fn set_signatures(&self, signatures: &SignatureList);
}

impl<O: IsA<DecryptResult>> DecryptResultExt for O {
    //fn get_cipher(&self) -> /*Ignored*/CipherAlgo {
    //    unsafe { TODO: call ffi::g_mime_decrypt_result_get_cipher() }
    //}

    fn get_mdc(&self) -> DigestAlgo {
        unsafe {
            from_glib(ffi::g_mime_decrypt_result_get_mdc(self.to_glib_none().0))
        }
    }

    fn get_recipients(&self) -> Option<CertificateList> {
        unsafe {
            from_glib_none(ffi::g_mime_decrypt_result_get_recipients(self.to_glib_none().0))
        }
    }

    fn get_session_key(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_decrypt_result_get_session_key(self.to_glib_none().0))
        }
    }

    fn get_signatures(&self) -> Option<SignatureList> {
        unsafe {
            from_glib_none(ffi::g_mime_decrypt_result_get_signatures(self.to_glib_none().0))
        }
    }

    //fn set_cipher(&self, cipher: /*Ignored*/CipherAlgo) {
    //    unsafe { TODO: call ffi::g_mime_decrypt_result_set_cipher() }
    //}

    fn set_mdc(&self, mdc: DigestAlgo) {
        unsafe {
            ffi::g_mime_decrypt_result_set_mdc(self.to_glib_none().0, mdc.to_glib());
        }
    }

    fn set_recipients(&self, recipients: &CertificateList) {
        unsafe {
            ffi::g_mime_decrypt_result_set_recipients(self.to_glib_none().0, recipients.to_glib_none().0);
        }
    }

    fn set_session_key<'a, P: Into<Option<&'a str>>>(&self, session_key: P) {
        let session_key = session_key.into();
        let session_key = session_key.to_glib_none();
        unsafe {
            ffi::g_mime_decrypt_result_set_session_key(self.to_glib_none().0, session_key.0);
        }
    }

    fn set_signatures(&self, signatures: &SignatureList) {
        unsafe {
            ffi::g_mime_decrypt_result_set_signatures(self.to_glib_none().0, signatures.to_glib_none().0);
        }
    }
}