code: def validate_key(key, sign=False, encrypt=False):
      
      if key.revoked:
          raise GPGProblem('The key "{}" is revoked.'.format(key.uids[0].uid),
                           code=GPGCode.KEY_REVOKED)
      elif key.expired:
          raise GPGProblem('The key "{}" is expired.'.format(key.uids[0].uid),
                           code=GPGCode.KEY_EXPIRED)
      elif key.invalid:
          raise GPGProblem('The key "{}" is invalid.'.format(key.uids[0].uid),
                           code=GPGCode.KEY_INVALID)
      if encrypt and not key.can_encrypt:
          raise GPGProblem(
              'The key "{}" cannot be used to encrypt'.format(key.uids[0].uid),
              code=GPGCode.KEY_CANNOT_ENCRYPT)
      if sign and not key.can_sign:
          raise GPGProblem(
              'The key "{}" cannot be used to sign'.format(key.uids[0].uid),
              code=GPGCode.KEY_CANNOT_SIGN)
docs: Assert that a key is valide and optionally that it can be used for
      signing or encrypting.  Raise GPGProblem otherwise.
  
      :param key: the GPG key to check
      :type key: gpg.gpgme._gpgme_key
      :param sign: whether the key should be able to sign
      :type sign: bool
      :param encrypt: whether the key should be able to encrypt
      :type encrypt: bool
      :raises ~alot.errors.GPGProblem: If the key is revoked, expired, or invalid
      :raises ~alot.errors.GPGProblem: If encrypt is true and the key cannot be
          used to encrypt
      :raises ~alot.errors.GPGProblem: If sign is true and th key cannot be used
          to encrypt