conform to draft-02: altitude in metres, checksum rewrite, strict decode #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "checksum-and-altitude-conformance"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Brings this crate into conformance with
draft-saywhere-geocoding-02. Companion toanuna/saywhere#21, which contains the spec change.Three divergences, in descending severity
Altitude was silently wrong
This crate still implemented draft-01's
altitude = units × 3.0 mstep model, sogrape.column.hip.toad:60decoded to 180 metres rather than the 60 the spec means. No error, no warning — just a wrong altitude.Draft-02 fixes altitude to signed metres above the WGS-84 ellipsoid per RFC 5870, and defines no alternative units.
The decoder failed open
On an invalid checksum it fell through and re-read the checksum word as a location word, instead of raising the error the spec requires — even though its own doc comment already claimed it errored. The comment justifying the fall-through ("many CHECKSUM-32 words also appear in BIP-39") was never true; zero of them do.
It also validated phrase length before stripping the checksum, so a valid 6-location-word phrase plus checksum (7 tokens) was rejected as too long — exactly the case the spec added a warning for.
The checksum vocabulary was stale
It disagreed with the spec and the Guile reference at 13 of 32 indices. The two implementations emitted different phrases for identical coordinates and rejected each other's checksummed phrases. Existing tests missed it because NYC lands on index 30, which happened to be
toadin both lists.Adopted design
Disjoint
CHECKSUM_CRC_32andCHECKSUM_ADD_31vocabularies — the trailing word selects the method, so exactly one checksum is computed rather than either being accepted — and a position-weighted additive checksum reduced modulo the prime 31, so detection is uniform (~3.2%) across error classes and word positions.Breaking API change
The crate is
0.1.0.encode_altitude/decode_altituderemoved — they existed only to implement the step modelencode_fullloses itsaltitude_stepparameterDecodeResult.altitude_units: Option<i32>→altitude_metres: Option<f64>AltitudeUnitsOutOfRange→InvalidAltitudeFormatparse_altitude_metres,format_altitude_metres,get_additive_checksum_word,expected_checksum_wordMigration: any stored
:Naltitude changes meaning. An old:20meant 60 m; it now means 20 m.Tests
151 pass. New tests pin:
gcd(4,32)=4bug cannot return silentlycolumn.grape.hipcollides withgrape.column.hip)TerminalChecksumFailedrather than falling throughVerified byte-identical to the Guile reference across 144 phrases (24 locations × 6 precisions) under both checksum methods.
Clippy: no new warnings (12 pre-existing style lints in test code, untouched).
🤖 Generated with Claude Code
https://claude.ai/code/session_017R8AwqxwAq8Av8GMZvLEPT
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.