diff --git a/cmd/meson.build b/cmd/meson.build index f87bfc35..fa5dfa55 100644 --- a/cmd/meson.build +++ b/cmd/meson.build @@ -1,27 +1,35 @@ -executable(meson.project_name(), - 'jose.c', 'jose.h', - 'b64/b64.h', - 'b64/dec.c', - 'b64/enc.c', - 'jwk/jwk.h', - 'jwk/eql.c', - 'jwk/exc.c', - 'jwk/gen.c', - 'jwk/pub.c', - 'jwk/thp.c', - 'jwk/use.c', - 'jws/jws.h', - 'jws/fmt.c', - 'jws/sig.c', - 'jws/ver.c', - 'jwe/jwe.h', - 'jwe/pwd.h', - 'jwe/fmt.c', - 'jwe/dec.c', - 'jwe/enc.c', - 'alg.c', - 'fmt.c', +rpath = '' +if buildtype == 'debug' or buildtype == 'debugoptimized' + rpath = libjose_build_dir +endif - dependencies: libjose_dep, - install: true -) +if (build_executable == true) + executable(meson.project_name(), + 'jose.c', 'jose.h', + 'b64/b64.h', + 'b64/dec.c', + 'b64/enc.c', + 'jwk/jwk.h', + 'jwk/eql.c', + 'jwk/exc.c', + 'jwk/gen.c', + 'jwk/pub.c', + 'jwk/thp.c', + 'jwk/use.c', + 'jws/jws.h', + 'jws/fmt.c', + 'jws/sig.c', + 'jws/ver.c', + 'jwe/jwe.h', + 'jwe/pwd.h', + 'jwe/fmt.c', + 'jwe/dec.c', + 'jwe/enc.c', + 'alg.c', + 'fmt.c', + + dependencies: libjose_dep, + install: true, + install_rpath: rpath + ) +endif diff --git a/lib/jwk.c b/lib/jwk.c index 626fc68f..79159221 100644 --- a/lib/jwk.c +++ b/lib/jwk.c @@ -24,6 +24,7 @@ #include #include #include +#include static bool jwk_hook(jose_cfg_t *cfg, json_t *jwk, jose_hook_jwk_kind_t kind) diff --git a/lib/meson.build b/lib/meson.build index e836e885..8705072b 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -1,12 +1,17 @@ -flags = '-Wl,--version-script=' + meson.current_source_dir() + '/libjose.map' -code = 'int main() { return 0; }' -cc = meson.get_compiler('c') +message ('Main lib') +if (build_dynamic == true) + message ('Adding the linker map') + flags = '-Wl,--version-script=' + meson.current_source_dir() + '/libjose.map' -if not cc.links(code, args: flags, name: '-Wl,--version-script=...') - flags = [ '-export-symbols-regex=^jose_.*' ] + code = 'int main() { return 0; }' + cc = meson.get_compiler('c') + if not cc.links(code, args: flags, name: '-Wl,--version-script=...') + flags = [ '-export-symbols-regex=^jose_.*' ] + endif endif -libjose_lib = shared_library('jose', +libjose_build_dir = meson.current_build_dir() +libjose_src = [ 'misc.c', 'misc.h', 'cfg.c', 'io.c', @@ -37,17 +42,41 @@ libjose_lib = shared_library('jose', 'openssl/pbes2.c', 'openssl/rsa.c', 'openssl/rsaes.c', - 'openssl/rsassa.c', - - include_directories: incdir, - dependencies: [zlib, jansson, libcrypto, threads], - version: '0.0.0', - link_args: flags, - install: true -) - -libjose_dep = declare_dependency( - include_directories: incdir, - dependencies: jansson, - link_with: libjose_lib -) + 'openssl/rsassa.c' +] + +if build_dynamic + libjose_lib = shared_library('jose', + libjose_src, + + include_directories: incdir, + dependencies: [zlib, jansson, libcrypto, threads], + version: '0.0.0', + link_args: flags, + install: true + ) + + + libjose_dep = declare_dependency( + include_directories: incdir, + dependencies: jansson, + link_with: libjose_lib + ) +endif + +# Define the static library using same sources and dependencies as libjose_lib +if build_static + libjose_static = static_library('jose_static', + libjose_src, + + include_directories: incdir, + dependencies: [zlib, jansson, libcrypto, threads], + ) + + # Declare the dependency for the static library + libjose_static_dep = declare_dependency( + include_directories: incdir, + dependencies: jansson, + link_with: libjose_static + ) +endif diff --git a/lib/openssl/aescbch.c b/lib/openssl/aescbch.c index c8d5e605..66cf338b 100644 --- a/lib/openssl/aescbch.c +++ b/lib/openssl/aescbch.c @@ -21,7 +21,7 @@ #include #include - +#include #include #define NAMES "A128CBC-HS256", "A192CBC-HS384", "A256CBC-HS512" @@ -36,6 +36,8 @@ typedef struct { uint64_t al; } io_t; +typedef int(init_t)(EVP_CIPHER_CTX *ctx, const EVP_CIPHER*, const unsigned char*,const unsigned char*); // EVP_EncryptInit + static uint64_t h2be64(uint64_t x) { @@ -274,7 +276,7 @@ dec_done(jose_io_t *io) static bool setup(const EVP_CIPHER *cph, const EVP_MD *md, jose_cfg_t *cfg, const json_t *jwe, const json_t *cek, uint8_t *iv, - typeof(EVP_EncryptInit) func, io_t *i) + init_t func, io_t *i) { uint8_t key[EVP_CIPHER_key_length(cph) * 2]; const char *aad = NULL; diff --git a/lib/openssl/aesgcm.c b/lib/openssl/aesgcm.c index b4f55f2d..dc122906 100644 --- a/lib/openssl/aesgcm.c +++ b/lib/openssl/aesgcm.c @@ -20,7 +20,7 @@ #include "../hooks.h" #include - +#include #include #define NAMES "A128GCM", "A192GCM", "A256GCM" @@ -33,10 +33,12 @@ typedef struct { json_t *json; } io_t; +typedef int(init_t)(EVP_CIPHER_CTX *ctx, const EVP_CIPHER*, ENGINE*, const unsigned char*,const unsigned char*); // EVP_EncryptInit_ex +typedef int(push_t)(EVP_CIPHER_CTX *ctx, unsigned char*, int*, const unsigned char*, int); // EVP_EncryptUpdate + static EVP_CIPHER_CTX * setup(const EVP_CIPHER *cph, jose_cfg_t *cfg, const json_t *jwe, - const json_t *cek, const uint8_t iv[], - typeof(EVP_EncryptInit_ex) *init, typeof(EVP_EncryptUpdate) *push) + const json_t *cek, const uint8_t iv[], init_t *init, push_t *push) { uint8_t key[EVP_CIPHER_key_length(cph)]; EVP_CIPHER_CTX *ecc = NULL; diff --git a/lib/openssl/rsassa.c b/lib/openssl/rsassa.c index 6b51df46..e585ae34 100644 --- a/lib/openssl/rsassa.c +++ b/lib/openssl/rsassa.c @@ -21,12 +21,12 @@ #include #include - +#include #include #define NAMES "RS256", "RS384", "RS512", "PS256", "PS384", "PS512" -typedef typeof(EVP_DigestSignInit) init_t; +typedef int (init_t)(EVP_MD_CTX*, EVP_PKEY_CTX**,const EVP_MD*, ENGINE*, EVP_PKEY*); // EVP_DigestSignInit declare_cleanup(EVP_PKEY) diff --git a/lib/zlib/deflate.c b/lib/zlib/deflate.c index 07eca0c9..7ccfc6c1 100644 --- a/lib/zlib/deflate.c +++ b/lib/zlib/deflate.c @@ -31,8 +31,11 @@ typedef struct { z_stream strm; } io_t; +typedef int(deflate_t)(z_streamp, int); // EVP_EncryptUpdate + + static bool -feed(jose_io_t *io, const void *in, size_t len, typeof(deflate) *func) +feed(jose_io_t *io, const void *in, size_t len, deflate_t *func) { io_t *i = containerof(io, io_t, io); @@ -65,7 +68,7 @@ feed(jose_io_t *io, const void *in, size_t len, typeof(deflate) *func) } static bool -done(jose_io_t *io, typeof(deflate) *func) +done(jose_io_t *io, deflate_t *func) { io_t *i = containerof(io, io_t, io); diff --git a/meson.build b/meson.build index b3308689..5c60e615 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,15 @@ project('jose', 'c', license: 'APL2', meson_version: '>=0.47.0', ) +buildtype = get_option('buildtype') +build_static = get_option('build_static') +build_dynamic = get_option('build_dynamic') +build_executable = get_option('build_executable') + +if (build_executable == true) + build_dynamic = true +endif + licensedir = join_paths(get_option('prefix'), 'share', 'licenses', meson.project_name()) if host_machine.system() == 'freebsd' licensedir += '-'+meson.project_version() @@ -53,6 +62,15 @@ subdir('tests') install_data(licenses, install_dir: licensedir) + +libraries = [] +if build_dynamic + libraries += libjose_lib +endif +if build_static + libraries += libjose_static +endif + pkg = import('pkgconfig') pkg.generate( description: 'Library for managing JOSE objects', @@ -60,7 +78,7 @@ pkg.generate( filebase: meson.project_name(), name: 'José Library', libraries_private: [ zlib, libcrypto ], - libraries: libjose_lib, + libraries: libraries, requires: jansson, ) diff --git a/meson_options.txt b/meson_options.txt index dd44146d..3b69e3c1 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,4 @@ option('docs', type: 'feature', description: 'Whether to build asciidoc manpages') +option('build_static', type: 'boolean', description: 'Build static library', value: false) +option('build_dynamic', type: 'boolean', description: 'Build dynamic library', value: true) +option('build_executable', type: 'boolean', description: 'Build the executable', value: true) diff --git a/tests/issue-75/meson.build b/tests/issue-75/meson.build index 67f518d4..e008f6f3 100644 --- a/tests/issue-75/meson.build +++ b/tests/issue-75/meson.build @@ -1,8 +1,10 @@ e = environment() -openssl = dependency('openssl', version: '>= 1.1.0', required: false) -if openssl.found() - issue75 = executable('issue75', 'issue-75.c', +if (build_executable == true) + openssl = dependency('openssl', version: '>= 1.1.0', required: false) + if openssl.found() + issue75 = executable('issue75', 'issue-75.c', dependencies: [libjose_dep, openssl]) - test('issue75', issue75, workdir : meson.current_source_dir(), env: e, timeout: 30) + test('issue75', issue75, workdir : meson.current_source_dir(), env: e, timeout: 30) + endif endif diff --git a/tests/meson.build b/tests/meson.build index 37b910a8..e065aef1 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -32,19 +32,21 @@ e = environment() e.prepend('PATH', meson.current_build_dir() + '/../cmd', separator: ':') e.set('VECTORS', meson.current_source_dir() + '/vectors') -foreach p: progs - exe = executable(p, p + '.c', dependencies: libjose_dep) - if p == 'api_b64' - to = 1800 - else - to = 180 - endif - test(p, exe, timeout: to) -endforeach +if (build_executable == true) + foreach p: progs + exe = executable(p, p + '.c', dependencies: libjose_dep) + if p == 'api_b64' + to = 1800 + else + to = 180 + endif + test(p, exe, timeout: to) + endforeach -foreach s: scripts - exe = find_program('./' + s) - test(s, exe, env: e, timeout: 900) -endforeach + foreach s: scripts + exe = find_program('./' + s) + test(s, exe, env: e, timeout: 900) + endforeach +endif subdir('issue-75')