Refactor to keep serialized Datalog#19
Merged
divarvel merged 3 commits intoJan 15, 2026
Merged
Conversation
Contributor
Author
|
Note this makes small breaking changes to the API, but #17 also was technically a breaking change. The next release should be 2.0.0. |
Currently, the Swift library does not keep a serialized representation of the Datalog contents of blocks, instead generating one on the fly when it is needed (for signature verification and to serialize the token). This is problematic because the serialization of a block is non-canonical and there are multiple valid serializations for the same block (which will not all pass signature verification). The current behavior is a mistake I made when implementing the library. This PR changes the behavior so that the `Biscuit.Block` type contains a `DatalogBlock` (the logical representation of its Datalog contents), a binary `serializedDatalog` field which is a valid serialization of that DatalogBlock, and the signautres on that serialization. The constructors for `Biscuit.Block` maintain the invariant that the serialization is a valid representation of the DatalogBlock by deriving one from the other and not allowing either to change after construction. This also enables other simplifications throughout the library. We no longer need to keep the internment tables for third party blocks around after serialization/deserialization, so we just keep the single, main internment table which will be used in attenuation. We don't need separate internment/serialization methods on the datalog types, because they are now always interned and serialized at the same time.
35f8b49 to
a982853
Compare
Contributor
|
Looks good, this is similar to how biscuit-haskell does things 👍 |
divarvel
approved these changes
Jan 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, the Swift library does not keep a serialized representation of the Datalog contents of blocks, instead generating one on the fly when it is needed (for signature verification and to serialize the token). This is problematic because the serialization of a block is non-canonical and there are multiple valid serializations for the same block (which will not all pass signature verification). The current behavior is a mistake I made when implementing the library.
This PR changes the behavior so that the
Biscuit.Blocktype contains aDatalogBlock(the logical representation of its Datalog contents), a binaryserializedDatalogfield which is a valid serialization of that DatalogBlock, and the signatures on that serialization. The constructors forBiscuit.Blockmaintain the invariant that the serialization is a valid representation of the DatalogBlock by deriving one from the other and not allowing either to change after construction.This also enables other simplifications throughout the library. We no longer need to keep the internment tables for third party blocks around after serialization/deserialization, so we just keep the single, main internment table which will be used in attenuation. We don't need separate internment/serialization methods on the datalog types, because they are now always interned and serialized at the same time. Several (internal) functions that could previous throw errors now cannot.