Пример #1
0
 def test_decode_b64jose_minimum_size(self):
     from acme.jose.json_util import decode_b64jose
     self.assertEqual(b'foo', decode_b64jose(u'Zm9v', size=3, minimum=True))
     self.assertEqual(b'foo', decode_b64jose(u'Zm9v', size=2, minimum=True))
     self.assertRaises(errors.DeserializationError,
                       decode_b64jose,
                       u'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=(cls.signature_cls.from_json(jobj),))
     else:
         return cls(payload=json_util.decode_b64jose(jobj['payload']),
                    signatures=tuple(cls.signature_cls.from_json(sig)
                                     for sig in jobj['signatures']))
Пример #3
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 = cls.signature_cls(protected=json_util.decode_b64jose(protected),
                             signature=json_util.decode_b64jose(signature))
     return cls(payload=json_util.decode_b64jose(payload), signatures=(sig,))
Пример #4
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=(cls.signature_cls.from_json(jobj), ))
     else:
         return cls(payload=json_util.decode_b64jose(jobj['payload']),
                    signatures=tuple(
                        cls.signature_cls.from_json(sig)
                        for sig in jobj['signatures']))
Пример #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 = cls.signature_cls(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 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):
     """Decode Base64urlUInt."""
     try:
         return int(binascii.hexlify(json_util.decode_b64jose(data)), 16)
     except ValueError:  # invalid literal for long() with base 16
         raise errors.DeserializationError()
Пример #8
0
 def fields_from_json(cls, jobj):
     return cls(key=json_util.decode_b64jose(jobj['k']))
Пример #9
0
 def protected(value):  # pylint: disable=missing-docstring,no-self-argument
     return json_util.decode_b64jose(value).decode('utf-8')
Пример #10
0
 def protected(value):  # pylint: disable=missing-docstring,no-self-argument
     return json_util.decode_b64jose(value).decode('utf-8')
 def test_decode_b64jose_minimum_size(self):
     from acme.jose.json_util import decode_b64jose
     self.assertEqual(b'foo', decode_b64jose(u'Zm9v', size=3, minimum=True))
     self.assertEqual(b'foo', decode_b64jose(u'Zm9v', size=2, minimum=True))
     self.assertRaises(errors.DeserializationError, decode_b64jose,
                       u'Zm9v', size=4, minimum=True)
 def test_decode_b64jose(self):
     from acme.jose.json_util import decode_b64jose
     decoded = decode_b64jose(u'eA')
     self.assertTrue(isinstance(decoded, six.binary_type))
     self.assertEqual(b'x', decoded)
Пример #13
0
 def test_decode_b64jose(self):
     from acme.jose.json_util import decode_b64jose
     decoded = decode_b64jose(u'eA')
     self.assertTrue(isinstance(decoded, six.binary_type))
     self.assertEqual(b'x', decoded)