Unify quotes in acme

This commit is contained in:
Jakub Warmuz 2015-02-04 20:24:15 +00:00
parent ebd9bbed90
commit 7515a9800c
No known key found for this signature in database
GPG key ID: 2A7BAD3A489B52EA
5 changed files with 28 additions and 27 deletions

View file

@ -10,7 +10,7 @@ from letsencrypt.acme import interfaces
def _leading_zeros(arg):
if len(arg) % 2:
return "0" + arg
return '0' + arg
return arg
@ -44,7 +44,7 @@ class JWK(object):
def _encode_param(cls, param):
"""Encode numeric key parameter."""
return b64encode(binascii.unhexlify(
_leading_zeros(hex(param)[2:].rstrip("L"))))
_leading_zeros(hex(param)[2:].rstrip('L'))))
@classmethod
def _decode_param(cls, param):
@ -54,18 +54,18 @@ class JWK(object):
def to_json(self):
"""Serialize to JSON."""
return {
"kty": "RSA", # TODO
"n": self._encode_param(self.key.n),
"e": self._encode_param(self.key.e),
'kty': 'RSA', # TODO
'n': self._encode_param(self.key.n),
'e': self._encode_param(self.key.e),
}
@classmethod
def from_json(cls, json_object):
"""Deserialize from JSON."""
assert "RSA" == json_object["kty"] # TODO
assert 'RSA' == json_object['kty'] # TODO
return cls(Crypto.PublicKey.RSA.construct(
(cls._decode_param(json_object["n"]),
cls._decode_param(json_object["e"]))))
(cls._decode_param(json_object['n']),
cls._decode_param(json_object['e']))))
# https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-37#appendix-C

View file

@ -123,5 +123,5 @@ class B64DecodeTest(unittest.TestCase):
self.assertRaises(TypeError, self._call, object())
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()

View file

@ -38,22 +38,22 @@ class MessageTest(unittest.TestCase):
def test_validate_unknown_type_fails(self):
self.assertRaises(errors.UnrecognnizedMessageTypeError,
self._validate, {"type": "bar"})
self._validate, {'type': 'bar'})
def test_validate_unregistered_type_fails(self):
self.assertRaises(errors.UnrecognnizedMessageTypeError,
self._validate, {"type": "foo"})
self._validate, {'type': 'foo'})
@mock.patch("letsencrypt.acme.messages.Message.TYPES")
@mock.patch('letsencrypt.acme.messages.Message.TYPES')
def test_validate_invalid_fails(self, types):
types.__getitem__.side_effect = lambda x: {"foo": "bar"}[x]
types.__getitem__.side_effect = lambda x: {'foo': 'bar'}[x]
self.assertRaises(errors.SchemaValidationError,
self._validate, {"type": "foo", "price": "asd"})
self._validate, {'type': 'foo', 'price': 'asd'})
@mock.patch("letsencrypt.acme.messages.Message.TYPES")
@mock.patch('letsencrypt.acme.messages.Message.TYPES')
def test_validate_valid_returns_cls(self, types):
types.__getitem__.side_effect = lambda x: {"foo": "bar"}[x]
self.assertEqual(self._validate({"type": "foo"}), "bar")
types.__getitem__.side_effect = lambda x: {'foo': 'bar'}[x]
self.assertEqual(self._validate({'type': 'foo'}), 'bar')
class ChallengeRequestTest(unittest.TestCase):

View file

@ -62,9 +62,9 @@ class Signature(object):
hashed = Crypto.Hash.SHA256.new(msg_with_nonce)
sig = Crypto.Signature.PKCS1_v1_5.new(key).sign(hashed)
logging.debug("%s signed as %s", msg_with_nonce, sig)
logging.debug('%s signed as %s', msg_with_nonce, sig)
return cls("RS256", sig, nonce, jose.JWK(key))
return cls('RS256', sig, nonce, jose.JWK(key))
def __eq__(self, other):
if isinstance(other, Signature):
@ -85,15 +85,15 @@ class Signature(object):
def to_json(self):
"""Seriliaze to JSON."""
return {
"alg": self.alg,
"sig": jose.b64encode(self.sig),
"nonce": jose.b64encode(self.nonce),
"jwk": self.jwk,
'alg': self.alg,
'sig': jose.b64encode(self.sig),
'nonce': jose.b64encode(self.nonce),
'jwk': self.jwk,
}
@classmethod
def from_json(cls, json_object):
"""Deserialize from JSON."""
return cls(json_object["alg"], jose.b64decode(json_object["sig"]),
jose.b64decode(json_object["nonce"]),
jose.JWK.from_json(json_object["jwk"]))
return cls(json_object['alg'], jose.b64decode(json_object['sig']),
jose.b64decode(json_object['nonce']),
jose.JWK.from_json(json_object['jwk']))

View file

@ -52,5 +52,6 @@ class SigatureTest(unittest.TestCase):
self.assertEqual(sig.alg, self.alg)
self.assertEqual(sig.jwk, self.jwk)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()