Move encode_cert() from hs_descriptor.c into torcert.c

Give it a better name, maybe improve the code to be a bit more generic and start using it in router.c at minimum.