Notes - String.reverse

Binaries are not always strings

The door access project moves a lot a binaries data about. A short while ago after the project had been in the wild for 16 months an odd error appeared.

Cards that should have been valid were being rejected.

After an investigation I tracked it down to a String.reverse call.

Data from the locks need to be reversed before doing any access checking. All worked fine until one day card data like the following turned up:

<<221, 152, 120, 6>>

Now string reverse on this does what it should and returns

<<6, 120, 221, 152>>

You can see that the first two bytes are copied and not reversed. Welcome to the world of UTF chars.

Conclusion

If you have binary data don’t treat it like a string, even though strings are binaries!