Skip to content

Commit

Permalink
[#2545] Fix invalid text in exceptions raised for invalid input.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgola committed Apr 8, 2016
1 parent cc73c99 commit a52685c
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 637 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -21,6 +21,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.eggs/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ python:
- "2.7"

install:
- pip install --extra-index-url http://chevah.com/pypi/simple --trusted-host chevah.com -e .[dev]
- pip install --extra-index-url https://pypi.chevah.com/simple -e .[dev]

script:
- python setup.py test -q
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Expand Up @@ -32,4 +32,4 @@ is Linux only::
# Trigger a builder
make test_remote TARGET=keycert-win-2008
# Trigger a builder with running the clean step
make test_remote_with_clean TARGET=keycert-win-2008
make test_remote_with_purge TARGET=keycert-win-2008
9 changes: 4 additions & 5 deletions Makefile
@@ -1,7 +1,7 @@
#
# Makefile for Chevah KeyCert project.
#
EXTRA_PYPI_INDEX='http://chevah.com/pypi/simple'
EXTRA_PYPI_INDEX='https://pypi.chevah.com/simple'

ifeq "$(MSYSTEM)" "MINGW32"
BASE_PATH='build/venv/Scripts'
Expand All @@ -20,7 +20,7 @@ all: test


local_env:
@if [ ! -d "build/venv" ]; then virtualenv build/venv; fi
@if [ ! -d "build/venv" ]; then virtualenv -p python2 build/venv; fi
@$(BASE_PATH)/pip install -U pip


Expand All @@ -30,7 +30,6 @@ deps: local_env deps_base
deps_base:
@$(BASE_PATH)/pip install \
--extra-index-url ${EXTRA_PYPI_INDEX}\
--trusted-host chevah.com \
-e .[dev]


Expand Down Expand Up @@ -75,8 +74,8 @@ else
$(BUILDBOT_TRY) -b $(TARGET)
endif

test_remote_with_clean: git_push
$(BUILDBOT_TRY) -b $(TARGET) --properties=force_clean=yes
test_remote_with_purge: git_push
$(BUILDBOT_TRY) -b $(TARGET) --properties=force_purge=yes

test_remote_with_wait: git_push
$(BUILDBOT_TRY) -b $(TARGET) --wait
48 changes: 40 additions & 8 deletions chevah/keycert/common.py
Expand Up @@ -5,11 +5,39 @@
Forked from twisted.conch.ssh.common
"""
import __builtin__
import struct

from __future__ import absolute_import, division
from Crypto import Util

import struct
import sys

_PY3 = sys.version_info > (3,)

if _PY3: # pragma: no cover
long = int
unicode = str
izip = zip

def native_string(s):
return s.decode("ascii")

def iterbytes(originalBytes):
for i in range(len(originalBytes)):
yield originalBytes[i:i + 1]
else:
import itertools
# So we can import from this module
long = long
unicode = unicode
izip = itertools.izip

def native_string(s):
return s

def iterbytes(originalBytes):
return originalBytes


def NS(t):
"""
Expand All @@ -33,11 +61,11 @@ def getNS(s, count=1):

def MP(number):
if number == 0:
return '\000' * 4
return b'\000' * 4
assert number > 0
bn = Util.number.long_to_bytes(number)
if ord(bn[0]) & 128:
bn = '\000' + bn
bn = b'\000' + bn
return struct.pack('>L', len(bn)) + bn


Expand All @@ -59,7 +87,8 @@ def getMP(data, count=1):


def _MPpow(x, y, z):
"""return the MP version of (x**y)%z
"""
Return the MP version of C{(x ** y) % z}.
"""
return MP(pow(x, y, z))

Expand All @@ -76,7 +105,7 @@ def _fastgetMP(data, count=1):
for i in range(count):
length = struct.unpack('!L', data[c:c + 4])[0]
mp.append(
long(gmpy.mpz(data[c + 4:c + 4 + length][::-1] + '\x00', 256)))
long(gmpy.mpz(data[c + 4:c + 4 + length][::-1] + b'\x00', 256)))
c += length + 4
return tuple(mp) + (data[c:],)

Expand All @@ -102,8 +131,11 @@ def _fastpow(x, y, z=None, mpz=gmpy.mpz):
if type(x) in (long, int):
x = mpz(x)
return pyPow(x, y, z)
__builtin__.pow = _fastpow # Ugly way of patching pow.

if not _PY3:
import __builtin__
__builtin__.pow = _fastpow # Ugly way of patching pow.
else:
__builtins__['pow'] = _fastpow

try:
import gmpy
Expand Down

0 comments on commit a52685c

Please sign in to comment.