mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:32:13 +02:00
Unify quotes in acme
This commit is contained in:
@@ -10,7 +10,7 @@ from letsencrypt.acme import interfaces
|
|||||||
|
|
||||||
def _leading_zeros(arg):
|
def _leading_zeros(arg):
|
||||||
if len(arg) % 2:
|
if len(arg) % 2:
|
||||||
return "0" + arg
|
return '0' + arg
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ class JWK(object):
|
|||||||
def _encode_param(cls, param):
|
def _encode_param(cls, param):
|
||||||
"""Encode numeric key parameter."""
|
"""Encode numeric key parameter."""
|
||||||
return b64encode(binascii.unhexlify(
|
return b64encode(binascii.unhexlify(
|
||||||
_leading_zeros(hex(param)[2:].rstrip("L"))))
|
_leading_zeros(hex(param)[2:].rstrip('L'))))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _decode_param(cls, param):
|
def _decode_param(cls, param):
|
||||||
@@ -54,18 +54,18 @@ class JWK(object):
|
|||||||
def to_json(self):
|
def to_json(self):
|
||||||
"""Serialize to JSON."""
|
"""Serialize to JSON."""
|
||||||
return {
|
return {
|
||||||
"kty": "RSA", # TODO
|
'kty': 'RSA', # TODO
|
||||||
"n": self._encode_param(self.key.n),
|
'n': self._encode_param(self.key.n),
|
||||||
"e": self._encode_param(self.key.e),
|
'e': self._encode_param(self.key.e),
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, json_object):
|
def from_json(cls, json_object):
|
||||||
"""Deserialize from JSON."""
|
"""Deserialize from JSON."""
|
||||||
assert "RSA" == json_object["kty"] # TODO
|
assert 'RSA' == json_object['kty'] # TODO
|
||||||
return cls(Crypto.PublicKey.RSA.construct(
|
return cls(Crypto.PublicKey.RSA.construct(
|
||||||
(cls._decode_param(json_object["n"]),
|
(cls._decode_param(json_object['n']),
|
||||||
cls._decode_param(json_object["e"]))))
|
cls._decode_param(json_object['e']))))
|
||||||
|
|
||||||
|
|
||||||
# https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-37#appendix-C
|
# https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-37#appendix-C
|
||||||
|
|||||||
@@ -123,5 +123,5 @@ class B64DecodeTest(unittest.TestCase):
|
|||||||
self.assertRaises(TypeError, self._call, object())
|
self.assertRaises(TypeError, self._call, object())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -38,22 +38,22 @@ class MessageTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_validate_unknown_type_fails(self):
|
def test_validate_unknown_type_fails(self):
|
||||||
self.assertRaises(errors.UnrecognnizedMessageTypeError,
|
self.assertRaises(errors.UnrecognnizedMessageTypeError,
|
||||||
self._validate, {"type": "bar"})
|
self._validate, {'type': 'bar'})
|
||||||
|
|
||||||
def test_validate_unregistered_type_fails(self):
|
def test_validate_unregistered_type_fails(self):
|
||||||
self.assertRaises(errors.UnrecognnizedMessageTypeError,
|
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):
|
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.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):
|
def test_validate_valid_returns_cls(self, types):
|
||||||
types.__getitem__.side_effect = lambda x: {"foo": "bar"}[x]
|
types.__getitem__.side_effect = lambda x: {'foo': 'bar'}[x]
|
||||||
self.assertEqual(self._validate({"type": "foo"}), "bar")
|
self.assertEqual(self._validate({'type': 'foo'}), 'bar')
|
||||||
|
|
||||||
|
|
||||||
class ChallengeRequestTest(unittest.TestCase):
|
class ChallengeRequestTest(unittest.TestCase):
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ class Signature(object):
|
|||||||
hashed = Crypto.Hash.SHA256.new(msg_with_nonce)
|
hashed = Crypto.Hash.SHA256.new(msg_with_nonce)
|
||||||
sig = Crypto.Signature.PKCS1_v1_5.new(key).sign(hashed)
|
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):
|
def __eq__(self, other):
|
||||||
if isinstance(other, Signature):
|
if isinstance(other, Signature):
|
||||||
@@ -85,15 +85,15 @@ class Signature(object):
|
|||||||
def to_json(self):
|
def to_json(self):
|
||||||
"""Seriliaze to JSON."""
|
"""Seriliaze to JSON."""
|
||||||
return {
|
return {
|
||||||
"alg": self.alg,
|
'alg': self.alg,
|
||||||
"sig": jose.b64encode(self.sig),
|
'sig': jose.b64encode(self.sig),
|
||||||
"nonce": jose.b64encode(self.nonce),
|
'nonce': jose.b64encode(self.nonce),
|
||||||
"jwk": self.jwk,
|
'jwk': self.jwk,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, json_object):
|
def from_json(cls, json_object):
|
||||||
"""Deserialize from JSON."""
|
"""Deserialize from JSON."""
|
||||||
return cls(json_object["alg"], jose.b64decode(json_object["sig"]),
|
return cls(json_object['alg'], jose.b64decode(json_object['sig']),
|
||||||
jose.b64decode(json_object["nonce"]),
|
jose.b64decode(json_object['nonce']),
|
||||||
jose.JWK.from_json(json_object["jwk"]))
|
jose.JWK.from_json(json_object['jwk']))
|
||||||
|
|||||||
@@ -52,5 +52,6 @@ class SigatureTest(unittest.TestCase):
|
|||||||
self.assertEqual(sig.alg, self.alg)
|
self.assertEqual(sig.alg, self.alg)
|
||||||
self.assertEqual(sig.jwk, self.jwk)
|
self.assertEqual(sig.jwk, self.jwk)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user