Skip to content

Commit

Permalink
xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
Synss committed May 5, 2019
1 parent 3a73413 commit 81bbe60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/mbedtls/_md.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ cdef extern from "mbedtls/md.h" nogil:
const mbedtls_md_info_t *md_info

const int *mbedtls_md_list()
const mbedtls_md_info_t *mbedtls_md_info_from_string(
const char *md_name)
const mbedtls_md_info_t *mbedtls_md_info_from_string(const char *md_name)
# mbedtls_md_info_from_type

void mbedtls_md_init(mbedtls_md_context_t *ctx)
Expand Down
23 changes: 13 additions & 10 deletions src/mbedtls/_md.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ cdef class MDBase:
name (str): The name of the message digest.
"""
def __init__(self, name, buffer, hmac):
if not isinstance(name, (str, unicode)):
raise TypeError("name must be a string: got %r" % name)
self._info = _md.mbedtls_md_info_from_string(
name.upper().encode("ascii"))
check_error(_md.mbedtls_md_setup(&self._ctx, self._info, hmac))
def __init__(self, name, _hmac):
name_ = name.upper().encode("ascii", "strict")
cdef char *c_name = name_
self._info = _md.mbedtls_md_info_from_string(c_name)
check_error(_md.mbedtls_md_setup(&self._ctx, self._info, _hmac))

def __cinit__(self):
"""Initialize an `md_context` (as NONE)."""
Expand Down Expand Up @@ -154,8 +153,8 @@ cdef class Hash(_md.MDBase):
name (str): The name of the message digest.
"""
def __init__(self, name, buffer=None):
super().__init__(name, buffer, 0)
def __init__(self, name, const unsigned char[:] buffer=None):
super().__init__(name, 0)
check_error(_md.mbedtls_md_starts(&self._ctx))
self.update(buffer)

Expand Down Expand Up @@ -201,8 +200,12 @@ cdef class Hmac(_md.MDBase):
"""
def __init__(
self, const unsigned char[:] key not None, name, buffer=None):
super().__init__(name, buffer, 1)
self,
const unsigned char[:] key not None,
name,
const unsigned char[:] buffer=None
):
super().__init__(name, 1)
if not key.size:
key = b"\0"
check_error(_md.mbedtls_md_hmac_starts(&self._ctx, &key[0], key.size))
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ passenv =
DYLD_LIBRARY_PATH
C_INCLUDE_PATH
commands =
cython --version
{envpython} -m pytest --basetemp={envtmpdir} {posargs}

[testenv:py37]
Expand Down

0 comments on commit 81bbe60

Please sign in to comment.