Skip to content

Commit

Permalink
Thread safe initialization of jansson and OpenSSL
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran authored and npmccallum committed Sep 30, 2016
1 parent c51a752 commit 66eef60
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions jansson.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ cdef extern from "jansson.h":
void json_decref(json_t *json)
json_t *json_loads(const char *input, size_t flags, json_error_t *error)
char *json_dumps(const json_t *json, size_t flags)

# misc
void json_object_seed(size_t seed)
4 changes: 4 additions & 0 deletions jose.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ cdef extern from "stdbool.h":
ctypedef signed char bool


cdef extern from "openssl/evp.h":
void OpenSSL_add_all_algorithms()


cdef extern from "jose/buf.h":
ctypedef struct jose_buf_t:
size_t size
Expand Down
16 changes: 16 additions & 0 deletions jose.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,19 @@ def to_compact(flat):
finally:
jansson.json_decref(cjose)
free(ret)


cdef init():
# init jansson hash randomization seed
jansson.json_object_seed(0)

# initialize OpenSSL
jose.OpenSSL_add_all_algorithms()

# try to import _ssl to set up threading locks
try:
__import__('_ssl')
except ImportError:
pass

init()

0 comments on commit 66eef60

Please sign in to comment.