| 1 | // public signature lists retain the actual GPGME key and its borrowed strings. |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | module engine |
| 4 | |
| 5 | // each non-null key_data entry owns one reference to release or transfer exactly once. |
| 6 | pub struct SignatureVerification { |
| 7 | pub: |
| 8 | results []SigResult |
| 9 | key_data []voidptr |
| 10 | } |
| 11 | |
| 12 | pub struct SignatureKeyView { |
| 13 | pub: |
| 14 | fingerprint &u8 = unsafe { nil } |
| 15 | uid &u8 = unsafe { nil } |
| 16 | name &u8 = unsafe { nil } |
| 17 | email &u8 = unsafe { nil } |
| 18 | } |
| 19 | |
| 20 | fn C.gpgme_key_ref(&C._gpgme_key) |
| 21 | |
| 22 | pub fn release_signature_keys(keys []voidptr) { |
| 23 | for key in keys { release_signature_key(key) } |
| 24 | } |
| 25 | |
| 26 | pub fn release_signature_key(key voidptr) { |
| 27 | if key != unsafe { nil } { C.gpgme_key_unref(unsafe { &C._gpgme_key(key) }) } |
| 28 | } |
| 29 | |
| 30 | pub fn signature_key_view(data voidptr) SignatureKeyView { |
| 31 | key := unsafe { &C._gpgme_key(data) } |
| 32 | if key == unsafe { nil } || key.subkeys == unsafe { nil } || key.uids == unsafe { nil } { |
| 33 | return SignatureKeyView{} |
| 34 | } |
| 35 | return SignatureKeyView{ |
| 36 | fingerprint: unsafe { &u8(key.subkeys.fpr) } |
| 37 | uid: unsafe { &u8(key.uids.uid) } |
| 38 | name: unsafe { &u8(key.uids.name) } |
| 39 | email: unsafe { &u8(key.uids.email) } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | pub fn (mut handle Handle) check_signature_owned(filename string, embedded ?string) !SignatureVerification { |
| 44 | handle.check()! |
| 45 | return handle.verify_signature(filename, embedded, true) or { |
| 46 | handle.log_signature_error(err) |
| 47 | return err |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | fn (handle &Handle) log_signature_error(problem IError) { |
| 52 | if problem is AlpmError { |
| 53 | if problem.kind == .gpgme { |
| 54 | handle.log(.error, localized_message('GPGME error: %s\n', problem.detail)) |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |