Repository navigation
A redesigned, minimal API and a decoder that locates pages and records through their sizes and offsets. Still Go 1.20, zero dependencies. From this release on, the v2 API changes only in backward-compatible ways.
go get github.com/moond4rk/binarycookies/v2@v2.0.0Breaking changes
- The module path is now
github.com/moond4rk/binarycookies/v2 binarycookies.Decode(r)replacesNew(r).Decode()and returns*File; use.Pagesor.Cookies()- Cookie fields are
stringinstead of[]byte,Secure()/HTTPOnly()are methods over the rawFlags,Creationis nowCreated, and times are in UTC - Removed
BinaryCookies,Page.Length,Page.Offsets,Cookie.SizeandCookie.String()
See the migration guide.
Fixed
- Flags are read bit by bit. Current Safari writes flag values such as
0x4205, which v1 decoded as neither Secure nor HttpOnly, so every cookie lost both attributes - A cookie record larger than 4096 bytes no longer makes the whole file fail to decode
- Page sizes and cookie/string offsets are honored, so padding is no longer misread without an error
- The comment no longer keeps its NUL terminator
- NaN or out-of-range timestamps decode to the zero time on every platform instead of platform-dependent values
- Allocation stays proportional to the input; a crafted 4 MiB file no longer allocates about 260 MiB
- A truncated file reports
io.ErrUnexpectedEOFinstead ofio.EOF
Added
Encode, which writes Safari's layout byte for byteErrInvalidSignatureandErrMalformed; a truncated file also matchesio.ErrUnexpectedEOF
Tests & CI
- Golden files for the Safari samples, table-driven tests for every decoding rule, and two fuzz targets
- CI on Linux, macOS and Windows with Go 1.20 and the latest Go, plus linux/386, fuzzing and an API compatibility check
- Verified against real Safari and WebKit data: 37 cookie files and 313 cookies decode, with v1 and v2 agreeing on everything except the corrected Secure/HttpOnly flags
What's Changed
Full Changelog: v1.0.3...v2.0.0