Add a low-allocation canonical sorting function that can be used in middleware. This implements the tests from rfc4034 correctly.