File: signature_service.py

package info (click to toggle)
python-braintree 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,376 kB
  • ctags: 1,998
  • sloc: python: 13,634; makefile: 73; sh: 8
file content (16 lines) | stat: -rw-r--r-- 521 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import urllib
from braintree.util.crypto import Crypto

class SignatureService(object):

    def __init__(self, private_key, hashfunc=Crypto.sha1_hmac_hash):
        self.private_key = private_key
        self.hmac_hash = hashfunc

    def sign(self, data):
        equalities = ['%s=%s' % (str(key), str(data[key])) for key in data]
        data_string = '&'.join(equalities)
        return "%s|%s" % (self.hash(data_string), data_string)

    def hash(self, data):
        return self.hmac_hash(self.private_key, data)