keyring: Refactored rsa & dh retrieval functions and tests