types: add ToJSON instances for base64 integer types

Add ToJSON instances for Base64Integer and SizedBase64Integer, and
tests for both encoding and decoding these types.

Also change SizedBase64Integer to store the size of the number in
bytes - not bits - to simplify the implementation.