Rewrite keyring pack/unpack code for extensibility