/src/suricata7/rust/src/x509/log.rs
Line | Count | Source |
1 | | /* Copyright (C) 2023 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | use crate::jsonbuilder::JsonBuilder; |
19 | | use crate::x509::time::format_timestamp; |
20 | | use std::ffi::CStr; |
21 | | use std::os::raw::c_char; |
22 | | |
23 | | /// Helper function to log a TLS timestamp from C to JSON with the |
24 | | /// provided key. The format of the timestamp is ISO 8601 timestamp |
25 | | /// with no sub-second or offset information as UTC is assumed. |
26 | | /// |
27 | | /// # Safety |
28 | | /// |
29 | | /// FFI function that dereferences pointers from C. |
30 | | #[no_mangle] |
31 | 3.30k | pub unsafe extern "C" fn sc_x509_log_timestamp( |
32 | 3.30k | jb: &mut JsonBuilder, key: *const c_char, timestamp: i64, |
33 | 3.30k | ) -> bool { |
34 | 3.30k | if let Ok(key) = CStr::from_ptr(key).to_str() { |
35 | 3.30k | if let Ok(timestamp) = format_timestamp(timestamp) { |
36 | 3.30k | return jb.set_string(key, ×tamp).is_ok(); |
37 | 0 | } |
38 | 0 | } |
39 | 0 | false |
40 | 3.30k | } |