Projet

Général

Profil

0001-wip.patch

Emmanuel Cazenave, 10 mars 2020 13:52

Télécharger (4,12 ko)

Voir les différences:

Subject: [PATCH] wip

 rfc3161/__init__.py |  6 +++---
 rfc3161/api.py      | 10 +++++-----
 setup.py            |  5 +++--
 tests/test_api.py   |  2 +-
 tox.ini             |  5 +++++
 5 files changed, 17 insertions(+), 11 deletions(-)
rfc3161/__init__.py
1
from types import *
2
from constants import *
3
from api import *
1
from .types import *
2
from .constants import *
3
from .api import *
4 4

  
5 5
VERSION = '1.0.6'
rfc3161/api.py
8 8
from pyasn1.type import univ
9 9
from pyasn1.error import PyAsn1Error
10 10
import M2Crypto.X509 as X509
11
import socket
11
import six
12 12

  
13 13
import rfc3161
14 14

  
......
49 49
            raise ValueError("extra data after tst")
50 50
        genTime = tstinfo.getComponentByName('genTime')
51 51
        return dateutil.parser.parse(str(genTime))
52
    except PyAsn1Error, e:
52
    except PyAsn1Error as e:
53 53
        raise ValueError('not a valid TimeStampToken', e)
54 54

  
55 55
def check_timestamp(tst, certificate, data=None, digest=None, hashname=None, nonce=None):
......
167 167
        message_imprint.setComponentByPosition(0, algorithm_identifier)
168 168
        hashobj = hashlib.new(self.hashname)
169 169
        if data:
170
            hashobj.update(data)
170
            hashobj.update(six.ensure_binary(data))
171 171
            digest = hashobj.digest()
172 172
        elif digest:
173 173
            assert len(digest) == hashobj.digest_size, 'digest length is wrong'
......
183 183
        binary_request = encoder.encode(request)
184 184
        headers = { 'Content-Type': 'application/timestamp-query' }
185 185
        if self.username != None:
186
            base64string = base64.standard_b64encode('%s:%s' % (self.username, self.password))
186
            base64string = base64.standard_b64encode(six.ensure_binary('%s:%s' % (self.username, self.password)))
187 187
            headers['Authorization'] = "Basic %s" % base64string
188 188
        try:
189 189
            response = requests.post(self.url, data=binary_request,
190 190
                    timeout=self.timeout, headers=headers)
191
        except request.RequestException, e:
191
        except request.RequestException as e:
192 192
            raise TimestampingError('Unable to send the request to %r' % self.url, e)
193 193
        tst_response, substrate = decoder.decode(response.content, asn1Spec=rfc3161.TimeStampResp())
194 194
        if substrate:
setup.py
6 6
      license='MIT',
7 7
      url='https://dev.entrouvert.org/projects/python-rfc3161',
8 8
      description='Python implementation of the RFC3161 specification, using pyasn1',
9
      long_description=file('README').read(),
9
      long_description=open('README').read(),
10 10
      author='Benjamin Dauvergne',
11 11
      author_email='bdauvergne@entrouvert.com',
12 12
      packages=['rfc3161'],
......
15 15
          'python-dateutil',
16 16
          'pyasn1_modules',
17 17
          'requests',
18
          'M2Crypto'])
18
          'M2Crypto',
19
          'six'])
tests/test_api.py
8 8

  
9 9
def default_test(tsa_server, certificate, username=None, password=None, data='xx', nonce=None, **kwargs):
10 10
    kwargs.update({
11
            'certificate': file(certificate).read()
11
            'certificate': open(certificate, 'rb').read()
12 12
    })
13 13
    if username and password:
14 14
        kwargs.update({
tox.ini
1
[tox]
2
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/python-rfc3161/{env:BRANCH_NAME:}
3
envlist = py2,py3
4

  
5

  
1 6
[testenv]
2 7
deps = 
3 8
  pytest-cov
4
-