From de0cdabb77fe87a9ca721bc71999bfae58ec54c1 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 17 Oct 2023 11:24:28 +0200 Subject: [PATCH] UnverifiedBiscuit: allow appending first-party blocks --- biscuit_test.py | 6 ++++++ src/lib.rs | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/biscuit_test.py b/biscuit_test.py index 0e1c0ea..fb63106 100644 --- a/biscuit_test.py +++ b/biscuit_test.py @@ -362,3 +362,9 @@ def test_unverified_biscuit_signature_check(): utoken = UnverifiedBiscuit.from_base64("Ep8BCjUKB3VzZXJfaWQKBWFsaWNlCgVmaWxlMRgDIgoKCAiACBIDGIEIIg4KDAgHEgMYgQgSAxiCCBIkCAASINFHns5iUW6aZiXA0GoqXyrpvFXrquiRGBZjPy3VJPoHGkAC0oew5bIngBkvg1FThYPBf30CAOBksyofzweJnmT_sQ5N4yT1xevHLImmPkJDFyJs9VXrQtroGy_UY5z3WREIGsgBCl4KATAKATEYAyouCgsIBBIDCIMIEgIYABIHCAISAwiDCBIICIAIEgMIhAgSDAgHEgMIhAgSAwiDCDIkCiIKAggbEgcIAhIDCIMIEgYIAxICGAASCwgEEgMIgwgSAhgAEiQIABIg2QCord1Cw30xC2Oea3AuAOPZ2Mvm9-EQmV3zN7zXwQEaQCLnXqIAz3srYrOJKY_g3slzt_nH5U52w8QYEdcuqCxoInvJB5t9BZht4X75MBzM3Aj1AjRVOGmH0ebuQ5GxnwYagwEKGQoFZmlsZTIYAyIOCgwIBxIDGIEIEgMYhQgSJAgAEiAMOoeV68xL1RTh_y4VeK3DUDBP_gnlPSsckzo87Pf7ihpAFAo2Mf7K5VC1HlC5uCK5R_tIXIAHCzRIL6EWzepWAUAWSh0KlZtA_tinJ-L2LAtXY1dgxIjIvw7agO5ZFVjECSIiCiBuSznFYC0NJn8VmDlZmiq1GpBSOERAwHjLZoQJG_24NA==") utoken.verify(public_key) + +def test_append_on_unverified(): + utoken = UnverifiedBiscuit.from_base64("Ep8BCjUKB3VzZXJfaWQKBWFsaWNlCgVmaWxlMRgDIgoKCAiACBIDGIEIIg4KDAgHEgMYgQgSAxiCCBIkCAASINFHns5iUW6aZiXA0GoqXyrpvFXrquiRGBZjPy3VJPoHGkAC0oew5bIngBkvg1FThYPBf30CAOBksyofzweJnmT_sQ5N4yT1xevHLImmPkJDFyJs9VXrQtroGy_UY5z3WREIGsgBCl4KATAKATEYAyouCgsIBBIDCIMIEgIYABIHCAISAwiDCBIICIAIEgMIhAgSDAgHEgMIhAgSAwiDCDIkCiIKAggbEgcIAhIDCIMIEgYIAxICGAASCwgEEgMIgwgSAhgAEiQIABIg2QCord1Cw30xC2Oea3AuAOPZ2Mvm9-EQmV3zN7zXwQEaQCLnXqIAz3srYrOJKY_g3slzt_nH5U52w8QYEdcuqCxoInvJB5t9BZht4X75MBzM3Aj1AjRVOGmH0ebuQ5GxnwYagwEKGQoFZmlsZTIYAyIOCgwIBxIDGIEIEgMYhQgSJAgAEiAMOoeV68xL1RTh_y4VeK3DUDBP_gnlPSsckzo87Pf7ihpAFAo2Mf7K5VC1HlC5uCK5R_tIXIAHCzRIL6EWzepWAUAWSh0KlZtA_tinJ-L2LAtXY1dgxIjIvw7agO5ZFVjECSIiCiBuSznFYC0NJn8VmDlZmiq1GpBSOERAwHjLZoQJG_24NA==") + + utoken2 = utoken.append(BlockBuilder("check if true")) + assert utoken2.block_source(3) == "check if true;\n" diff --git a/src/lib.rs b/src/lib.rs index dc6051a..388870b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1115,6 +1115,19 @@ impl PyUnverifiedBiscuit { .map_err(|e| BiscuitBlockError::new_err(e.to_string())) } + /// Create a new `UnverifiedBiscuit` by appending an attenuation block + /// + /// :param block: a builder for the new block + /// :type block: BlockBuilder + /// :return: the attenuated biscuit + /// :rtype: Biscuit + pub fn append(&self, block: &PyBlockBuilder) -> PyResult { + self.0 + .append(block.0.clone()) + .map_err(|e| BiscuitBuildError::new_err(e.to_string())) + .map(PyUnverifiedBiscuit) + } + /// The revocation ids of the token, encoded as hexadecimal strings #[getter] pub fn revocation_ids(&self) -> Vec {