Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the meson build declaration to #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions cmd/meson.build
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/jwk.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

static bool
jwk_hook(jose_cfg_t *cfg, json_t *jwk, jose_hook_jwk_kind_t kind)
Expand Down
69 changes: 49 additions & 20 deletions lib/meson.build
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions lib/openssl/aescbch.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <openssl/rand.h>
#include <openssl/sha.h>

#include <openssl/evp.h>
#include <string.h>

#define NAMES "A128CBC-HS256", "A192CBC-HS384", "A256CBC-HS512"
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions lib/openssl/aesgcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../hooks.h"

#include <openssl/rand.h>

#include <openssl/evp.h>
#include <string.h>

#define NAMES "A128GCM", "A192GCM", "A256GCM"
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/openssl/rsassa.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#include <jose/openssl.h>

#include <openssl/sha.h>

#include <openssl/evp.h>
#include <string.h>

#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)

Expand Down
7 changes: 5 additions & 2 deletions lib/zlib/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
20 changes: 19 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -53,14 +62,23 @@ 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',
version: meson.project_version(),
filebase: meson.project_name(),
name: 'José Library',
libraries_private: [ zlib, libcrypto ],
libraries: libjose_lib,
libraries: libraries,
requires: jansson,
)

Expand Down
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 6 additions & 4 deletions tests/issue-75/meson.build
Original file line number Diff line number Diff line change
@@ -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
28 changes: 15 additions & 13 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')