Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
9eba70e1
Commit
9eba70e1
authored
11 years ago
by
Donald Stufft
Browse files
Options
Downloads
Patches
Plain Diff
Don't compile on import
parent
fbbe466f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
nacl/nacl.py
+60
-18
60 additions, 18 deletions
nacl/nacl.py
with
60 additions
and
18 deletions
nacl/nacl.py
+
60
−
18
View file @
9eba70e1
...
@@ -5,8 +5,10 @@ from __future__ import absolute_import
...
@@ -5,8 +5,10 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
division
import
functools
import
functools
import
os.path
from
cffi
import
FFI
from
cffi
import
FFI
from
cffi.verifier
import
Verifier
__all__
=
[
"
ffi
"
,
"
lib
"
]
__all__
=
[
"
ffi
"
,
"
lib
"
]
...
@@ -74,7 +76,19 @@ ffi.cdef(
...
@@ -74,7 +76,19 @@ ffi.cdef(
)
)
lib
=
ffi
.
verify
(
"
#include <sodium.h>
"
,
libraries
=
[
"
sodium
"
])
#lib = ffi.verify("#include <sodium.h>", libraries=["sodium"])
ffi
.
verifier
=
Verifier
(
ffi
,
"
#include <sodium.h>
"
,
# We need to set a tmp directory otherwise when build_ext is run it'll get
# built in nacl/*.so but when ffi.verifier.load_library() is run it'll
# look (and ultimately build again) in nacl/__pycache__/*.so
tmpdir
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)),
# We need to link to the sodium library
libraries
=
[
"
sodium
"
],
)
# This works around a bug in PyPy where CFFI exposed functions do not have a
# This works around a bug in PyPy where CFFI exposed functions do not have a
...
@@ -99,20 +113,48 @@ def wrap_nacl_function(func):
...
@@ -99,20 +113,48 @@ def wrap_nacl_function(func):
return
ret
==
0
return
ret
==
0
return
wrapper
return
wrapper
lib
.
crypto_secretbox
=
wrap_nacl_function
(
lib
.
crypto_secretbox
)
lib
.
crypto_secretbox_open
=
wrap_nacl_function
(
lib
.
crypto_secretbox_open
)
lib
.
crypto_sign_seed_keypair
=
wrap_nacl_function
(
lib
.
crypto_sign_seed_keypair
)
class
Library
(
object
):
lib
.
crypto_sign
=
wrap_nacl_function
(
lib
.
crypto_sign
)
lib
.
crypto_sign_open
=
wrap_nacl_function
(
lib
.
crypto_sign_open
)
wrap
=
[
"
crypto_secretbox
"
,
"
crypto_secretbox_open
"
,
"
crypto_sign_seed_keypair
"
,
"
crypto_sign
"
,
"
crypto_sign_open
"
,
"
crypto_box_keypair
"
,
"
crypto_box_afternm
"
,
"
crypto_box_open_afternm
"
,
"
crypto_box_beforenm
"
,
"
crypto_hash
"
,
"
crypto_hash_sha256
"
,
"
crypto_hash_sha512
"
,
"
crypto_scalarmult_curve25519_base
"
,
]
def
__init__
(
self
,
ffi
):
self
.
_ffi
=
ffi
self
.
_initalized
=
False
def
__getattr__
(
self
,
name
):
if
not
self
.
_initalized
:
self
.
_lib
=
self
.
_ffi
.
verifier
.
load_library
()
# redirect attribute access to the underlying lib
attr
=
getattr
(
self
.
_lib
,
name
)
# If this is a function that we're wrapping do the actual wrapping
if
name
in
self
.
wrap
:
attr
=
wrap_nacl_function
(
attr
)
lib
.
crypto_box_keypair
=
wrap_nacl_function
(
lib
.
crypto_box_keypair
)
# Go ahead and assign the returned value to this class so we don't
lib
.
crypto_box_afternm
=
wrap_nacl_function
(
lib
.
crypto_box_afternm
)
# need to do this lookup again
lib
.
crypto_box_open_afternm
=
wrap_nacl_function
(
lib
.
crypto_box_open_afternm
)
setattr
(
self
,
name
,
attr
)
lib
.
crypto_box_beforenm
=
wrap_nacl_function
(
lib
.
crypto_box_beforenm
)
lib
.
crypto_hash
=
wrap_nacl_function
(
lib
.
crypto_hash
)
return
attr
lib
.
crypto_hash_sha256
=
wrap_nacl_function
(
lib
.
crypto_hash_sha256
)
lib
.
crypto_hash_sha512
=
wrap_nacl_function
(
lib
.
crypto_hash_sha512
)
lib
.
crypto_scalarmult_curve25519_base
=
wrap_nacl_function
(
lib
.
crypto_scalarmult_curve25519_base
)
lib
=
Library
(
ffi
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment