Refactor writeSignedAP and writeUnsignedAP

They were almost exact duplicates except for the Writer used to write
the tag.