Merge gpgme-vala into openpgp plugin

There's no reason for it to be a statically linked library anymore, it
can be directly compiled into the plugin.
This commit is contained in:
hrxi 2023-06-04 09:24:16 +02:00 committed by fiaxh
parent dd0038f5e2
commit e2d801b5f7
10 changed files with 192 additions and 256 deletions

View file

@ -2,8 +2,5 @@ foreach(plugin ${PLUGINS})
if ("omemo" STREQUAL ${plugin}) if ("omemo" STREQUAL ${plugin})
add_subdirectory(signal-protocol) add_subdirectory(signal-protocol)
endif () endif ()
if ("openpgp" STREQUAL ${plugin})
add_subdirectory(gpgme-vala)
endif ()
add_subdirectory(${plugin}) add_subdirectory(${plugin})
endforeach(plugin) endforeach(plugin)

View file

@ -1,52 +0,0 @@
find_package(GPGME REQUIRED)
find_packages(GPGME_VALA_PACKAGES REQUIRED
Gee
GLib
GObject
)
vala_precompile(GPGME_VALA_C
SOURCES
"src/gpgme_helper.vala"
CUSTOM_VAPIS
"${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme.vapi"
"${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme_public.vapi"
"${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpg-error.vapi"
PACKAGES
${GPGME_VALA_PACKAGES}
GENERATE_VAPI
gpgme-vala
GENERATE_HEADER
gpgme-vala
)
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/gpgme_fix.h"
COMMAND
cp "${CMAKE_CURRENT_SOURCE_DIR}/src/gpgme_fix.h" "${CMAKE_BINARY_DIR}/exports/gpgme_fix.h"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/gpgme_fix.h"
COMMENT
Copy header file gpgme_fix.h
)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/exports/gpgme.vapi
COMMAND
cat "${CMAKE_BINARY_DIR}/exports/gpgme-vala.vapi" "${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme_public.vapi" > "${CMAKE_BINARY_DIR}/exports/gpgme.vapi"
DEPENDS
${CMAKE_BINARY_DIR}/exports/gpgme-vala.vapi
${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme_public.vapi
)
add_custom_target(gpgme-vapi
DEPENDS
${CMAKE_BINARY_DIR}/exports/gpgme_fix.h
${CMAKE_BINARY_DIR}/exports/gpgme.vapi
)
set(CFLAGS ${VALA_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/src)
add_definitions(${CFLAGS})
add_library(gpgme-vala STATIC ${GPGME_VALA_C} src/gpgme_fix.c)
add_dependencies(gpgme-vala gpgme-vapi)
target_link_libraries(gpgme-vala ${GPGME_VALA_PACKAGES} gpgme)
set_property(TARGET gpgme-vala PROPERTY POSITION_INDEPENDENT_CODE ON)

View file

@ -1 +0,0 @@
gpg-error

View file

@ -1,162 +0,0 @@
[CCode (lower_case_cprefix = "gpgme_", cheader_filename = "gpgme.h,gpgme_fix.h")]
namespace GPG {
[CCode (cname = "gpgme_check_version")]
public unowned string check_version(string? required_version = null);
[Compact]
[CCode (cname = "struct _gpgme_key", ref_function = "gpgme_key_ref_vapi", unref_function = "gpgme_key_unref_vapi", free_function = "gpgme_key_release")]
public class Key {
public bool revoked;
public bool expired;
public bool disabled;
public bool invalid;
public bool can_encrypt;
public bool can_sign;
public bool can_certify;
public bool can_authenticate;
public bool is_qualified;
public bool secret;
public Protocol protocol;
public string issuer_serial;
public string issuer_name;
public string chain_id;
public Validity owner_trust;
[CCode(array_null_terminated = true)]
public SubKey[] subkeys;
[CCode(array_null_terminated = true)]
public UserID[] uids;
public KeylistMode keylist_mode;
// public string fpr; // requires gpgme >= 1.7.0
public string fpr { get { return subkeys[0].fpr; } }
}
[CCode (cname = "struct _gpgme_user_id")]
public struct UserID {
UserID* next;
bool revoked;
bool invalid;
Validity validity;
string uid;
string name;
string email;
string comment;
KeySig signatures;
}
[CCode (cname = "struct _gpgme_key_sig")]
public struct KeySig {
KeySig* next;
bool invoked;
bool expired;
bool invalid;
bool exportable;
PublicKeyAlgorithm algo;
string keyid;
long timestamp;
long expires;
// GPGError.Error status;
string uid;
string name;
string email;
string comment;
uint sig_class;
SigNotation notations;
}
[CCode (cname = "struct _gpgme_subkey")]
public struct SubKey {
SubKey* next;
bool revoked;
bool expired;
bool disabled;
bool invalid;
bool can_encrypt;
bool can_sign;
bool can_certify;
bool secret;
bool can_authenticate;
bool is_qualified;
bool is_cardkey;
PublicKeyAlgorithm algo;
uint length;
string keyid;
string fpr;
long timestamp;
long expires;
string? cardnumber;
}
[CCode (cname = "struct _gpgme_sig_notation")]
public struct SigNotation {
SigNotation* next;
string? name;
string value;
int name_len;
int value_len;
SigNotationFlags flags;
bool human_readable;
bool critical;
}
[CCode (cname = "gpgme_sig_notation_flags_t", cprefix = "GPGME_SIG_NOTATION_")]
public enum SigNotationFlags {
HUMAN_READABLE,
CRITICAL
}
[CCode (cname = "gpgme_sig_mode_t", cprefix = "GPGME_SIG_MODE_")]
public enum SigMode {
NORMAL,
DETACH,
CLEAR
}
[CCode (cname = "gpgme_encrypt_flags_t", cprefix = "GPGME_ENCRYPT_")]
public enum EncryptFlags {
ALWAYS_TRUST,
NO_ENCRYPT_TO
}
[CCode (cname = "gpgme_pubkey_algo_t", cprefix = "GPGME_PK_")]
public enum PublicKeyAlgorithm {
RSA,
RSA_E,
RSA_S,
ELG_E,
DSA,
ELG
}
[CCode (cname = "gpgme_protocol_t", cprefix = "GPGME_PROTOCOL_")]
public enum Protocol {
OpenPGP,
CMS,
GPGCONF,
ASSUAN,
UNKNOWN
}
[CCode (cname = "gpgme_keylist_mode_t", cprefix = "GPGME_KEYLIST_MODE_")]
public enum KeylistMode {
LOCAL,
EXTERN,
SIGS,
SIG_NOTATIONS,
EPHEMERAL,
VALIDATE
}
[CCode (cname = "gpgme_validity_t", cprefix = "GPGME_VALIDITY_")]
public enum Validity {
UNKNOWN,
UNDEFINED,
NEVER,
MARGINAL,
FULL,
ULTIMATE
}
}

View file

@ -1,3 +1,5 @@
find_package(GPGME REQUIRED)
set(GETTEXT_PACKAGE "dino-openpgp") set(GETTEXT_PACKAGE "dino-openpgp")
find_package(Gettext) find_package(Gettext)
include(${GETTEXT_USE_FILE}) include(${GETTEXT_USE_FILE})
@ -28,6 +30,8 @@ compile_gresources(
vala_precompile(OPENPGP_VALA_C vala_precompile(OPENPGP_VALA_C
SOURCES SOURCES
src/gpgme_helper.vala
src/file_transfer/file_decryptor.vala src/file_transfer/file_decryptor.vala
src/file_transfer/file_encryptor.vala src/file_transfer/file_encryptor.vala
@ -42,7 +46,8 @@ SOURCES
src/stream_module.vala src/stream_module.vala
src/util.vala src/util.vala
CUSTOM_VAPIS CUSTOM_VAPIS
${CMAKE_BINARY_DIR}/exports/gpgme.vapi ${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme.vapi
${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpg-error.vapi
${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi
${CMAKE_BINARY_DIR}/exports/qlite.vapi ${CMAKE_BINARY_DIR}/exports/qlite.vapi
${CMAKE_BINARY_DIR}/exports/dino.vapi ${CMAKE_BINARY_DIR}/exports/dino.vapi
@ -53,9 +58,10 @@ GRESOURCES
) )
add_definitions(${VALA_CFLAGS} -DG_LOG_DOMAIN="OpenPGP" -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\") add_definitions(${VALA_CFLAGS} -DG_LOG_DOMAIN="OpenPGP" -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\")
add_library(openpgp SHARED ${OPENPGP_VALA_C} ${OPENPGP_GRESOURCES_TARGET}) add_library(openpgp SHARED ${OPENPGP_VALA_C} ${OPENPGP_GRESOURCES_TARGET} src/gpgme_fix.c)
add_dependencies(openpgp ${GETTEXT_PACKAGE}-translations) add_dependencies(openpgp ${GETTEXT_PACKAGE}-translations)
target_link_libraries(openpgp libdino gpgme-vala ${OPENPGP_PACKAGES}) target_include_directories(openpgp PRIVATE src)
target_link_libraries(openpgp libdino gpgme ${OPENPGP_PACKAGES})
set_target_properties(openpgp PROPERTIES PREFIX "") set_target_properties(openpgp PROPERTIES PREFIX "")
set_target_properties(openpgp PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/) set_target_properties(openpgp PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/)

View file

@ -441,11 +441,5 @@ namespace GPGError {
public Error.from_errno (ErrorSource source, int err); public Error.from_errno (ErrorSource source, int err);
public ErrorCode code { [CCode (cname = "gpg_err_code")] get; } public ErrorCode code { [CCode (cname = "gpg_err_code")] get; }
public ErrorSource source { [CCode (cname = "gpg_err_source")] get; } public ErrorSource source { [CCode (cname = "gpg_err_source")] get; }
[CCode (cname = "gpg_strerror")]
public unowned string to_string ();
[CCode (cname = "gpg_strsource")]
public unowned string source_to_string ();
} }
} }

View file

@ -1,6 +1,7 @@
/* libgpgme.vapi /* libgpgme.vapi
* *
* Copyright (C) 2009 Sebastian Reichel <sre@ring0.de> * Copyright (C) 2009 Sebastian Reichel <sre@ring0.de>
* Copyright (C) 2022 Itay Grudev <itay+git2022@grudev.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -36,6 +37,100 @@ namespace GPG {
string? home_dir; string? home_dir;
} }
[Compact]
[CCode (cname = "struct _gpgme_key", ref_function = "gpgme_key_ref", ref_function_void = true, unref_function = "gpgme_key_unref", free_function = "gpgme_key_release")]
public class Key {
public bool revoked;
public bool expired;
public bool disabled;
public bool invalid;
public bool can_encrypt;
public bool can_sign;
public bool can_certify;
public bool secret;
public bool can_authenticate;
public bool is_qualified;
public Protocol protocol;
public string issuer_serial;
public string issuer_name;
public string chain_id;
public Validity owner_trust;
[CCode(array_null_terminated = true)]
public SubKey[] subkeys;
[CCode(array_null_terminated = true)]
public UserID[] uids;
public KeylistMode keylist_mode;
public string fpr { get { return subkeys[0].fpr; } }
}
[CCode (cname = "struct _gpgme_sig_notation")]
public struct SigNotation {
SigNotation* next;
string? name;
string value;
int name_len;
int value_len;
SigNotationFlags flags;
bool human_readable;
bool critical;
}
[CCode (cname = "struct _gpgme_subkey")]
public struct SubKey {
SubKey* next;
bool revoked;
bool expired;
bool disabled;
bool invalid;
bool can_encrypt;
bool can_sign;
bool can_certify;
bool secret;
bool can_authenticate;
bool is_qualified;
bool is_cardkey;
PublicKeyAlgorithm algo;
uint length;
string keyid;
string fpr;
long timestamp;
long expires;
string? card_number;
}
[CCode (cname = "struct _gpgme_key_sig")]
public struct KeySig {
KeySig* next;
bool revoked;
bool expired;
bool invalid;
bool exportable;
PublicKeyAlgorithm algo;
string keyid;
long timestamp;
long expires;
GPGError.Error status;
string uid;
string name;
string email;
string comment;
uint sig_class;
SigNotation notations;
}
[CCode (cname = "struct _gpgme_user_id")]
public struct UserID {
UserID* next;
bool revoked;
bool invalid;
Validity validity;
string uid;
string name;
string email;
string comment;
KeySig signatures;
}
[CCode (cname = "struct _gpgme_op_verify_result")] [CCode (cname = "struct _gpgme_op_verify_result")]
public struct VerifyResult { public struct VerifyResult {
Signature* signatures; Signature* signatures;
@ -92,7 +187,7 @@ namespace GPG {
GPGError.Error validity_reason; GPGError.Error validity_reason;
PublicKeyAlgorithm pubkey_algo; PublicKeyAlgorithm pubkey_algo;
HashAlgorithm hash_algo; HashAlgorithm hash_algo;
string? pka_adress; string? pka_address;
} }
public enum PKAStatus { public enum PKAStatus {
@ -128,6 +223,16 @@ namespace GPG {
URL0 URL0
} }
[CCode (cname = "gpgme_pubkey_algo_t", cprefix = "GPGME_PK_")]
public enum PublicKeyAlgorithm {
RSA,
RSA_E,
RSA_S,
ELG_E,
DSA,
ELG
}
[CCode (cname = "gpgme_hash_algo_t", cprefix = "GPGME_MD_")] [CCode (cname = "gpgme_hash_algo_t", cprefix = "GPGME_MD_")]
public enum HashAlgorithm { public enum HashAlgorithm {
NONE, NONE,
@ -141,9 +246,45 @@ namespace GPG {
SHA384, SHA384,
SHA512, SHA512,
MD4, MD4,
MD_CRC32, CRC32,
MD_CRC32_RFC1510, CRC32_RFC1510,
MD_CRC24_RFC2440 CRC24_RFC2440
}
[CCode (cname = "gpgme_sig_mode_t", cprefix = "GPGME_SIG_MODE_")]
public enum SigMode {
NORMAL,
DETACH,
CLEAR
}
[CCode (cname = "gpgme_validity_t", cprefix = "GPGME_VALIDITY_")]
public enum Validity {
UNKNOWN,
UNDEFINED,
NEVER,
MARGINAL,
FULL,
ULTIMATE
}
[CCode (cname = "gpgme_protocol_t", cprefix = "GPGME_PROTOCOL_")]
public enum Protocol {
OpenPGP,
CMS,
GPGCONF,
ASSUAN,
UNKNOWN
}
[CCode (cname = "gpgme_keylist_mode_t", cprefix = "GPGME_KEYLIST_MODE_")]
public enum KeylistMode {
LOCAL,
EXTERN,
SIGS,
SIG_NOTATIONS,
EPHEMERAL,
VALIDATE
} }
[CCode (cname = "gpgme_export_mode_t", cprefix = "GPGME_EXPORT_MODE_")] [CCode (cname = "gpgme_export_mode_t", cprefix = "GPGME_EXPORT_MODE_")]
@ -157,6 +298,18 @@ namespace GPG {
WITH_HELP WITH_HELP
} }
[CCode (cname = "gpgme_sig_notation_flags_t", cprefix = "GPGME_SIG_NOTATION_")]
public enum SigNotationFlags {
HUMAN_READABLE,
CRITICAL
}
[CCode (cname = "gpgme_encrypt_flags_t", cprefix = "GPGME_ENCRYPT_")]
public enum EncryptFlags {
ALWAYS_TRUST,
NO_ENCRYPT_TO
}
[CCode (cname = "gpgme_status_code_t", cprefix = "GPGME_STATUS_")] [CCode (cname = "gpgme_status_code_t", cprefix = "GPGME_STATUS_")]
public enum StatusCode { public enum StatusCode {
EOF, EOF,
@ -244,21 +397,6 @@ namespace GPG {
PLAINTEXT PLAINTEXT
} }
[Flags]
[CCode (cname="unsigned int")]
public enum ImportStatusFlags {
[CCode (cname = "GPGME_IMPORT_NEW")]
NEW,
[CCode (cname = "GPGME_IMPORT_UID")]
UID,
[CCode (cname = "GPGME_IMPORT_SIG")]
SIG,
[CCode (cname = "GPGME_IMPORT_SUBKEY")]
SUBKEY,
[CCode (cname = "GPGME_IMPORT_SECRET")]
SECRET
}
[Compact] [Compact]
[CCode (cname = "struct gpgme_context", free_function = "gpgme_release", cprefix = "gpgme_")] [CCode (cname = "struct gpgme_context", free_function = "gpgme_release", cprefix = "gpgme_")]
public class Context { public class Context {
@ -405,10 +543,24 @@ namespace GPG {
public KeylistResult op_keylist_result(); public KeylistResult op_keylist_result();
} }
[Flags]
[CCode (cname="unsigned int")]
public enum ImportStatusFlags {
[CCode (cname = "GPGME_IMPORT_NEW")]
NEW,
[CCode (cname = "GPGME_IMPORT_UID")]
UID,
[CCode (cname = "GPGME_IMPORT_SIG")]
SIG,
[CCode (cname = "GPGME_IMPORT_SUBKEY")]
SUBKEY,
[CCode (cname = "GPGME_IMPORT_SECRET")]
SECRET
}
[Compact] [Compact]
[CCode (cname = "struct _gpgme_import_status")] [CCode (cname = "struct _gpgme_import_status")]
public class ImportStatus { public class ImportStatus {
public ImportStatus? next; public ImportStatus? next;
public string fpr; public string fpr;
public GPGError.Error result; public GPGError.Error result;
@ -452,7 +604,6 @@ namespace GPG {
return data; return data;
} }
[CCode (cname = "gpgme_data_new_from_mem")] [CCode (cname = "gpgme_data_new_from_mem")]
public static GPGError.Error new_from_memory(out Data d, char[] buffer, bool copy); public static GPGError.Error new_from_memory(out Data d, char[] buffer, bool copy);
@ -499,11 +650,14 @@ namespace GPG {
[CCode (cname = "gpgme_passphrase_cb_t", has_target = false)] [CCode (cname = "gpgme_passphrase_cb_t", has_target = false)]
public delegate GPGError.Error passphrase_callback(void* hook, string uid_hint, string passphrase_info, bool prev_was_bad, int fd); public delegate GPGError.Error passphrase_callback(void* hook, string uid_hint, string passphrase_info, bool prev_was_bad, int fd);
[CCode (cname = "gpgme_check_version")]
public unowned string check_version(string? required_version = null);
[CCode (cname = "gpgme_engine_check_version")] [CCode (cname = "gpgme_engine_check_version")]
public GPGError.Error engine_check_version(Protocol proto); public GPGError.Error engine_check_version(Protocol proto);
[CCode (cname = "gpgme_get_engine_information")] [CCode (cname = "gpgme_get_engine_info")]
public GPGError.Error get_engine_information(out EngineInfo engine_info); public GPGError.Error get_engine_info(out EngineInfo? engine_info);
[CCode (cname = "gpgme_strerror_r")] [CCode (cname = "gpgme_strerror_r")]
public int strerror_r(GPGError.Error err, uint8[] buf); public int strerror_r(GPGError.Error err, uint8[] buf);