Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
4540be74
Commit
4540be74
authored
8 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
python: add more crypto bindings
parent
7c85b74d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/opendht/crypto.h
+4
-1
4 additions, 1 deletion
include/opendht/crypto.h
python/opendht.pyx
+34
-2
34 additions, 2 deletions
python/opendht.pyx
python/opendht_cpp.pxd
+8
-0
8 additions, 0 deletions
python/opendht_cpp.pxd
with
46 additions
and
3 deletions
include/opendht/crypto.h
+
4
−
1
View file @
4540be74
...
@@ -250,7 +250,10 @@ struct OPENDHT_PUBLIC Certificate {
...
@@ -250,7 +250,10 @@ struct OPENDHT_PUBLIC Certificate {
* ordered from subject to issuer
* ordered from subject to issuer
*/
*/
Certificate
(
const
Blob
&
crt
);
Certificate
(
const
Blob
&
crt
);
Certificate
(
const
uint8_t
*
dat
,
size_t
dat_size
)
{
Certificate
(
const
std
::
string
&
pem
)
:
cert
(
nullptr
)
{
unpack
((
const
uint8_t
*
)
pem
.
data
(),
pem
.
size
());
}
Certificate
(
const
uint8_t
*
dat
,
size_t
dat_size
)
:
cert
(
nullptr
)
{
unpack
(
dat
,
dat_size
);
unpack
(
dat
,
dat_size
);
}
}
...
...
This diff is collapsed.
Click to expand it.
python/opendht.pyx
+
34
−
2
View file @
4540be74
...
@@ -241,6 +241,24 @@ cdef class NodeSet(object):
...
@@ -241,6 +241,24 @@ cdef class NodeSet(object):
def
__iter__
(
self
):
def
__iter__
(
self
):
return
NodeSetIter
(
self
)
return
NodeSetIter
(
self
)
cdef
class
PrivateKey
(
_WithID
):
cdef
cpp
.
PrivateKey
_key
def
getId
(
self
):
h
=
InfoHash
()
h
.
_infohash
=
self
.
_key
.
getPublicKey
().
getId
()
return
h
def
getPublicKey
(
self
):
pk
=
PublicKey
()
pk
.
_key
=
self
.
_key
.
getPublicKey
()
return
pk
def
__str__
(
self
):
return
self
.
getId
().
toString
().
decode
()
@staticmethod
def
generate
():
k
=
PrivateKey
()
k
.
_key
=
cpp
.
PrivateKey
.
generate
()
return
k
cdef
class
PublicKey
(
_WithID
):
cdef
class
PublicKey
(
_WithID
):
cdef
cpp
.
PublicKey
_key
cdef
cpp
.
PublicKey
_key
def
getId
(
self
):
def
getId
(
self
):
...
@@ -250,10 +268,23 @@ cdef class PublicKey(_WithID):
...
@@ -250,10 +268,23 @@ cdef class PublicKey(_WithID):
cdef
class
Certificate
(
_WithID
):
cdef
class
Certificate
(
_WithID
):
cdef
shared_ptr
[
cpp
.
Certificate
]
_cert
cdef
shared_ptr
[
cpp
.
Certificate
]
_cert
def
__init__
(
self
,
bytes
dat
=
None
):
if
dat
:
self
.
_cert
=
cpp
.
make_shared
[
cpp
.
Certificate
](
<
cpp
.
string
>
dat
)
def
getId
(
self
):
def
getId
(
self
):
h
=
InfoHash
()
h
=
InfoHash
()
if
self
.
_cert
:
h
.
_infohash
=
self
.
_cert
.
get
().
getId
()
h
.
_infohash
=
self
.
_cert
.
get
().
getId
()
return
h
return
h
def
toString
(
self
):
return
self
.
_cert
.
get
().
toString
().
decode
()
@staticmethod
def
generate
(
PrivateKey
k
,
str
name
,
Identity
i
=
Identity
(),
bool
is_ca
=
False
):
c
=
Certificate
()
c
.
_cert
=
cpp
.
make_shared
[
cpp
.
Certificate
](
cpp
.
Certificate
.
generate
(
k
.
_key
,
name
.
encode
(),
i
.
_id
,
is_ca
))
return
c
def
__bytes__
(
self
):
return
self
.
_cert
.
get
().
toString
()
if
self
.
_cert
else
b
''
cdef
class
ListenToken
(
object
):
cdef
class
ListenToken
(
object
):
cdef
cpp
.
InfoHash
_h
cdef
cpp
.
InfoHash
_h
...
@@ -297,6 +328,7 @@ cdef class DhtRunner(_WithID):
...
@@ -297,6 +328,7 @@ cdef class DhtRunner(_WithID):
self
.
thisptr
.
reset
(
new
cpp
.
DhtRunner
())
self
.
thisptr
.
reset
(
new
cpp
.
DhtRunner
())
def
getId
(
self
):
def
getId
(
self
):
h
=
InfoHash
()
h
=
InfoHash
()
if
self
.
thisptr
:
h
.
_infohash
=
self
.
thisptr
.
get
().
getId
()
h
.
_infohash
=
self
.
thisptr
.
get
().
getId
()
return
h
return
h
def
getNodeId
(
self
):
def
getNodeId
(
self
):
...
...
This diff is collapsed.
Click to expand it.
python/opendht_cpp.pxd
+
8
−
0
View file @
4540be74
...
@@ -32,7 +32,9 @@ cdef extern from "<memory>" namespace "std" nogil:
...
@@ -32,7 +32,9 @@ cdef extern from "<memory>" namespace "std" nogil:
shared_ptr
(
T
*
)
except
+
shared_ptr
(
T
*
)
except
+
T
*
get
()
T
*
get
()
T
operator
*
()
T
operator
*
()
bool
operator
bool
()
const
void
reset
(
T
*
)
void
reset
(
T
*
)
shared_ptr
[
T
]
make_shared
[
T
](...)
except
+
cdef
extern
from
"
<functional>
"
namespace
"
std
"
nogil
:
cdef
extern
from
"
<functional>
"
namespace
"
std
"
nogil
:
cdef
cppclass
hash
[
T
]:
cdef
cppclass
hash
[
T
]:
...
@@ -82,6 +84,8 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto":
...
@@ -82,6 +84,8 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto":
cdef
cppclass
PrivateKey
:
cdef
cppclass
PrivateKey
:
PrivateKey
()
PrivateKey
()
PublicKey
getPublicKey
()
const
PublicKey
getPublicKey
()
const
@staticmethod
PrivateKey
generate
()
cdef
cppclass
PublicKey
:
cdef
cppclass
PublicKey
:
PublicKey
()
PublicKey
()
...
@@ -89,7 +93,11 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto":
...
@@ -89,7 +93,11 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto":
cdef
cppclass
Certificate
:
cdef
cppclass
Certificate
:
Certificate
()
Certificate
()
Certificate
(
string
pem
)
InfoHash
getId
()
const
InfoHash
getId
()
const
string
toString
()
const
@staticmethod
Certificate
generate
(
PrivateKey
key
,
string
name
,
Identity
ca
,
bool
is_ca
)
cdef
extern
from
"
opendht/value.h
"
namespace
"
dht
"
:
cdef
extern
from
"
opendht/value.h
"
namespace
"
dht
"
:
cdef
cppclass
Value
:
cdef
cppclass
Value
:
...
...
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