summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/src/packet/literal.rs
blob: 7bb25844b406453e38c4476235371cc8a07b859f (plain)
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
//! Literal data packets.
//!
//! Literal data packets hold the actual message content and some
//! optional meta-data.
//!
//! See [Section 5.8 of RFC 4880] for details.
//!
//!   [Section 5.8 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.8

use libc::c_char;

use sequoia_openpgp as openpgp;

use super::Packet;

use crate::MoveFromRaw;
use crate::MoveIntoRaw;
use crate::RefRaw;

/// Holds a Literal Data packet.
///
/// Literal data packets hold the actual message content and some
/// optional meta-data.
///
/// See [Section 5.8 of RFC 4880] for details.
///
///   [Section 5.8 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.8
///
/// Wraps [`sequoia-openpgp::packet::literal::Literal`].
///
/// [`sequoia-openpgp::packet::literal::Literal`]: ../../../../sequoia_openpgp/packet/literal/struct.Literal.html
#[crate::ffi_wrapper_type(prefix = "pgp_",
                     derive = "Debug, Parse")]
pub struct Literal(openpgp::packet::Literal);

/// Converts the literal data packet to a packet.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C"
fn pgp_literal_into_packet(l: *mut Literal) -> *mut Packet {
    let p : openpgp::Packet = l.move_from_raw().into();
    p.move_into_raw()
}

/// Returns the filename as a c string.
///
/// If the filename is not set, returns NULL.
///
/// Note: the filename is *not* protected by any signature and thus
/// can be modified in transit without detection.
///
/// Note: the filename may contain embedded NULs.  This function
/// returns NULL in such cases.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C"
fn pgp_literal_filename(l: *const Literal) -> *mut c_char {
    let l : &openpgp::packet::Literal = l.ref_raw();
    if let Some(filename) = l.filename() {
        ffi_return_maybe_string!(filename)
    } else {
        ::std::ptr::null_mut()
    }
}