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

Split up functions into multiple modules #5

Closed
npmccallum opened this issue Sep 28, 2016 · 4 comments
Closed

Split up functions into multiple modules #5

npmccallum opened this issue Sep 28, 2016 · 4 comments
Assignees

Comments

@npmccallum
Copy link
Contributor

Instead of this:

import jose
jose.jwk_generate({"alg": "A128GCM"})

We want this:

import jose.jwk
jose.jwk.generate({"alg": "A128GCM"})
@npmccallum
Copy link
Contributor Author

This might get tricky around the compact conversion functions. I definitely want:

import jose
jose.to_compact(...)
jose.from_compact(...)

@npmccallum npmccallum assigned npmccallum and tiran and unassigned npmccallum Sep 28, 2016
@tiran
Copy link
Member

tiran commented Sep 29, 2016

There are multiple ways to accomplish your goal. The simplest way is to rename the C extension _jose and then introduce a jose package and modules:

jose/__init__.py
jose/_jose.so
jose/jwk.py

Each module imports the function it is interested in:

# jwk.py
from ._jose import jwk_generate as generate

or wraps the functions:

# jwk.py
from . import _jose

def generate(jwk):
    return _jose.jwk_generate(jwk)

@npmccallum
Copy link
Contributor Author

Regarding module layout, I'm thinking:

jose.jwk.generate()
jose.jwk.clean()
jose.jwk.allowed()
jose.jwk.thumbprint()
jose.jwk.exchange()

jose.jws.sign()
jose.jws.verify()
jose.jws.merge_header()

jose.jwe.wrap()
jose.jwe.encrypt()
jose.jwe.unwrap()
jose.jwe.decrypt()
jose.jwe.merge_header()

jose.compact.dumps()
jose.compact.loads()

The main change here is that jose_to_compact() and jose_from_compact() become just serialization functions for a JWS/JWE object. This mimics the json module. The base jose module would be empty.

I think this layout should be easy to make. Something like:

jose/__init__.py
jose/jwk.so
jose/jws.so
jose/jwe.so
jose/compact.so

Thoughts?

@tiran
Copy link
Member

tiran commented Sep 30, 2016

I advice against multiple shared libraries. It's a common practice to have an internal C module and do the rest in Python -- one internal shared library and a couple of Python modules as facade.

It's easier, faster and simpler for development, too.In Python 2 a C extension does not have the ability to support sub-namespaces in packages. You can't easily share data between C extensions, e.g. exception types. Cython makes it a bit easier but it is still hacky.

Layout

jose/__init__.py
jose/_jose.so
jose/jwk.py
jose/jws.py
jose/jwe.py
jose/compact.py

tiran added a commit to tiran/pyjose that referenced this issue Oct 4, 2016
Closes: latchset#5
Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/pyjose that referenced this issue Oct 5, 2016
Closes: latchset#5
Signed-off-by: Christian Heimes <cheimes@redhat.com>
@tiran tiran closed this as completed in #22 Oct 5, 2016
tiran added a commit that referenced this issue Oct 5, 2016
Closes: #5
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants