|
8 | 8 | from .utils import * |
9 | 9 |
|
10 | 10 |
|
| 11 | +DEFAULT_SIGN_ALGORITHM = "hmac-sha256" |
| 12 | + |
| 13 | + |
11 | 14 | class Signer(object): |
12 | 15 | """ |
13 | 16 | When using an RSA algo, the secret is a PEM-encoded private key. |
14 | 17 | When using an HMAC algo, the secret is the HMAC signing secret. |
15 | 18 | |
16 | 19 | Password-protected keyfiles are not supported. |
17 | 20 | """ |
18 | | - def __init__(self, secret, algorithm='rsa-sha256'): |
| 21 | + def __init__(self, secret, algorithm=None): |
| 22 | + if algorithm is None: |
| 23 | + algorithm = DEFAULT_SIGN_ALGORITHM |
| 24 | + |
19 | 25 | assert algorithm in ALGORITHMS, "Unknown algorithm" |
20 | 26 | if isinstance(secret, six.string_types): secret = secret.encode("ascii") |
21 | 27 |
|
@@ -67,12 +73,15 @@ class HeaderSigner(Signer): |
67 | 73 | Generic object that will sign headers as a dictionary using the http-signature scheme. |
68 | 74 | https://github.com/joyent/node-http-signature/blob/master/http_signing.md |
69 | 75 |
|
70 | | - key_id is the mandatory label indicating to the server which secret to use |
71 | | - secret is the filename of a pem file in the case of rsa, a password string in the case of an hmac algorithm |
72 | | - algorithm is one of the six specified algorithms |
73 | | - headers is a list of http headers to be included in the signing string, defaulting to ['date']. |
| 76 | + :arg key_id: the mandatory label indicating to the server which secret to use |
| 77 | + :arg secret: a PEM-encoded RSA private key or an HMAC secret (must match the algorithm) |
| 78 | + :arg algorithm: one of the six specified algorithms |
| 79 | + :arg headers: a list of http headers to be included in the signing string, defaulting to ['date']. |
74 | 80 | ''' |
75 | | - def __init__(self, key_id, secret, algorithm='rsa-sha256', headers=None): |
| 81 | + def __init__(self, key_id, secret, algorithm=None, headers=None): |
| 82 | + if algorithm is None: |
| 83 | + algorithm = DEFAULT_SIGN_ALGORITHM |
| 84 | + |
76 | 85 | super(HeaderSigner, self).__init__(secret=secret, algorithm=algorithm) |
77 | 86 | self.headers = headers or ['date'] |
78 | 87 | self.signature_template = build_signature_template(key_id, algorithm, headers) |
|
0 commit comments