def test_decode_b64_jose_minimum_size(self):
     from letsencrypt.acme.jose.json_util import decode_b64jose
     self.assertEqual('foo', decode_b64jose('Zm9v', size=3, minimum=True))
     self.assertEqual('foo', decode_b64jose('Zm9v', size=2, minimum=True))
     self.assertRaises(errors.DeserializationError,
                       decode_b64jose,
                       'Zm9v',
                       size=4,
                       minimum=True)
示例#2
0
 def from_json(cls, jobj):
     if 'signature' in jobj and 'signatures' in jobj:
         raise errors.DeserializationError('Flat mixed with non-flat')
     elif 'signature' in jobj:  # flat
         return cls(payload=json_util.decode_b64jose(jobj.pop('payload')),
                    signatures=(Signature.from_json(jobj),))
     else:
         return cls(payload=json_util.decode_b64jose(jobj['payload']),
                    signatures=tuple(Signature.from_json(sig)
                                     for sig in jobj['signatures']))
示例#3
0
 def from_json(cls, jobj):
     if 'signature' in jobj and 'signatures' in jobj:
         raise errors.DeserializationError('Flat mixed with non-flat')
     elif 'signature' in jobj:  # flat
         return cls(payload=json_util.decode_b64jose(jobj.pop('payload')),
                    signatures=(Signature.from_json(jobj),))
     else:
         return cls(payload=json_util.decode_b64jose(jobj['payload']),
                    signatures=tuple(Signature.from_json(sig)
                                     for sig in jobj['signatures']))
示例#4
0
 def from_compact(cls, compact):
     """Compact deserialization."""
     try:
         protected, payload, signature = compact.split('.')
     except ValueError:
         raise errors.DeserializationError(
             'Compact JWS serialization should comprise of exactly'
             ' 3 dot-separated components')
     sig = Signature(protected=json_util.decode_b64jose(protected),
                     signature=json_util.decode_b64jose(signature))
     return cls(payload=json_util.decode_b64jose(payload), signatures=(sig,))
示例#5
0
 def from_compact(cls, compact):
     """Compact deserialization."""
     try:
         protected, payload, signature = compact.split('.')
     except ValueError:
         raise errors.DeserializationError(
             'Compact JWS serialization should comprise of exactly'
             ' 3 dot-separated components')
     sig = Signature(protected=json_util.decode_b64jose(protected),
                     signature=json_util.decode_b64jose(signature))
     return cls(payload=json_util.decode_b64jose(payload), signatures=(sig,))
 def test_decode_b64_jose_size(self):
     from letsencrypt.acme.jose.json_util import decode_b64jose
     self.assertEqual('foo', decode_b64jose('Zm9v', size=3))
     self.assertRaises(
         errors.DeserializationError, decode_b64jose, 'Zm9v', size=2)
     self.assertRaises(
         errors.DeserializationError, decode_b64jose, 'Zm9v', size=4)
示例#7
0
 def _decode_param(cls, data):
     try:
         return long(binascii.hexlify(json_util.decode_b64jose(data)), 16)
     except ValueError:  # invalid literal for long() with base 16
         raise errors.DeserializationError()
示例#8
0
 def _decode_param(cls, data):
     try:
         return long(binascii.hexlify(json_util.decode_b64jose(data)), 16)
     except ValueError:  # invalid literal for long() with base 16
         raise errors.DeserializationError()