I have a first draft. See branch ticket32207 with PR at https://github.com/torproject/tor/pull/1547
Thanks! Overall, it looks good. I made a minor comment on the pull request. Feel free to merge once you've addressed it.
It could probably use more improvement but I'm lacking concrete suggestions for doing so. Maybe next time I have to write or modify code that touches it, I'll think of some.