Skip to content

Commit

Permalink
Mark untestable lines "no cover"
Browse files Browse the repository at this point in the history
  • Loading branch information
Synss committed Mar 6, 2020
1 parent 22979d3 commit 815621a
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
plugins = Cython.Coverage

[report]
exclude_lines =
pragma: no cover
include =
src/*
8 changes: 4 additions & 4 deletions src/mbedtls/_md.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ cdef class MDBase:
cdef unsigned char* output = <unsigned char*>malloc(
sz * sizeof(unsigned char))
if not output:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
check_error(self._finish(output))
return bytes(output[:self.digest_size])
finally:
free(output)
free(output) # pragma: no cover

def hexdigest(self):
"""Like digest except the digest is returned as a string object
Expand All @@ -132,7 +132,7 @@ cdef class MDBase:

def copy(self):
"""Return a copy ("clone") of the MD object."""
raise NotImplementedError
raise NotImplementedError # pragma: no cover


cdef class Hash(_md.MDBase):
Expand Down Expand Up @@ -229,4 +229,4 @@ cdef class Hmac(_md.MDBase):
Not implemented in mbed TLS, raises NotImplementedError.
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover
8 changes: 4 additions & 4 deletions src/mbedtls/_random.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ cdef class _Entropy:
length * sizeof(unsigned char)
)
if not output:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
check_error(_rnd.mbedtls_entropy_func(&self._ctx, output, length))
return bytes(output[:length])
finally:
free(output)
free(output) # pragma: no cover

def update(self, const unsigned char[:] data):
"""Add data to the accumulator manually."""
Expand Down Expand Up @@ -85,7 +85,7 @@ cdef class Random:
length * sizeof(unsigned char)
)
if not output:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
check_error(
_rnd.mbedtls_ctr_drbg_random(&self._ctx, output, length)
Expand All @@ -94,7 +94,7 @@ cdef class Random:
_plt.mbedtls_platform_zeroize(output, length)
return ret
finally:
free(output)
free(output) # pragma: no cover

def _reseed(self, const unsigned char[:] data=None):
"""Reseed the RNG."""
Expand Down
4 changes: 2 additions & 2 deletions src/mbedtls/exceptions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TLSError(Exception):
cdef size_t buflen = 200
cdef char* buffer = <char*>malloc(buflen * sizeof(char))
if not buffer:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
_err.mbedtls_strerror(self.err, &buffer[0], buflen)
output = bytes(buffer[:buflen])
Expand All @@ -42,7 +42,7 @@ class TLSError(Exception):
olen = buflen
return output[:olen].decode("ascii")
finally:
free(buffer)
free(buffer) # pragma: no cover

def __str__(self):
if self.err is None:
Expand Down
12 changes: 6 additions & 6 deletions src/mbedtls/hkdf.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def hkdf(
length * sizeof(unsigned char)
)
if not okm:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
check_error(_hkdf.mbedtls_hkdf(
hmac._info,
Expand All @@ -61,7 +61,7 @@ def hkdf(
))
return bytes(okm[:length])
finally:
free(okm)
free(okm) # pragma: no cover


def extract(
Expand Down Expand Up @@ -94,7 +94,7 @@ def extract(
hmac.digest_size * sizeof(unsigned char)
)
if not prk:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
check_error(_hkdf.mbedtls_hkdf_extract(
hmac._info,
Expand All @@ -105,7 +105,7 @@ def extract(
))
return bytes(prk[:hmac.digest_size])
finally:
free(prk)
free(prk) # pragma: no cover


def expand(
Expand Down Expand Up @@ -139,7 +139,7 @@ def expand(
length * sizeof(unsigned char)
)
if not okm:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
check_error(_hkdf.mbedtls_hkdf_expand(
hmac._info,
Expand All @@ -150,4 +150,4 @@ def expand(
))
return bytes(okm[:length])
finally:
free(okm)
free(okm) # pragma: no cover
2 changes: 1 addition & 1 deletion src/mbedtls/mpi.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ cdef class MPI:
cdef size_t _len(self)


cdef inline from_mpi(mbedtls_mpi *c_mpi):
cdef inline from_mpi(mbedtls_mpi *c_mpi): # pragma: no cover
new_mpi = MPI()
mbedtls_mpi_copy(&new_mpi._ctx, c_mpi)
return new_mpi
4 changes: 2 additions & 2 deletions src/mbedtls/mpi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ cdef class MPI:
cdef unsigned char* output = <unsigned char*>malloc(
length * sizeof(unsigned char))
if not output:
raise MemoryError()
raise MemoryError() # pragma: no cover
try:
check_error(_mpi.mbedtls_mpi_write_binary(
&self._ctx, output, length))
return bytes(output[:length])[::-1 if byteorder == "little" else 1]
except Exception as exc:
raise OverflowError from exc
finally:
free(output)
free(output) # pragma: no cover

__bytes__ = to_bytes

Expand Down

0 comments on commit 815621a

Please sign in to comment.