Skip to content

Commit

Permalink
Tighten JsonPointer and methods
Browse files Browse the repository at this point in the history
The `JsonPointer` type ought to be `#[repr(transparent)]` if
`std::mem::transmute` is going to be used to coerce one from a `str`.
`ReferenceToken` already did.

The `validate` method did not ensure that a string starts with a `/`. This
may not have led a direct path to any undefined behavior, because it was
ensured that all `~` are followed by a `0` or `1`, but other methods do
act as though they assumed a pointer string always starts with a `/`. I
think this makes things a bit more clear.

The private `token_end` can be mostly replaced by `find("/")`.

`as_array_index` can be implemented in terms of the standard library's
integer parsing. (Allowing "+000" is an annoying gotcha in seemingly
every major language's standard library!).

I've added `Deserialize` for `&JsonPointer`.

I've made the internals of the new `json_pointer!` macro `const {}` to
better ensure that its checks actually happen at compile time.

I've adjusted some methods to reduce the total number of `unsafe` blocks
necessary.
  • Loading branch information
jeddenlea committed Sep 19, 2024
1 parent a585e0c commit f5b0079
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 115 deletions.
5 changes: 4 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ documentation = "https://docs.rs/ssi-core/"
thiserror.workspace = true
async-trait.workspace = true
serde = { workspace = true, features = ["derive"] }
pin-project.workspace = true
pin-project.workspace = true

[dev-dependencies]
serde_json.workspace = true
Loading

0 comments on commit f5b0079

Please sign in to comment.