def verify_signature(public_key, scheme, signature, data, use_pynacl=False):
<EOL>securesystemslib.formats.ED25519PUBLIC_SCHEMA.check_match(public_key)<EOL>securesystemslib.formats.ED25519_SIG_SCHEMA.check_match(scheme)<EOL>securesystemslib.formats.ED25519SIGNATURE_SCHEMA.check_match(signature)<EOL>securesystemslib.formats.BOOLEAN_SCHEMA.check_match(use_pynacl)<EOL>public = public_key<EOL>valid_signature = False<EOL>if scheme in _SUPPORTED_ED25519_SIGNING_SCHEMES:<EOL><INDENT>if use_pynacl:<EOL><INDENT>try:<EOL><INDENT>nacl_verify_key = nacl.signing.VerifyKey(public)<EOL>nacl_message = nacl_verify_key.verify(data, signature)<EOL>valid_signature = True<EOL><DEDENT>except NameError: <EOL><INDENT>raise securesystemslib.exceptions.UnsupportedLibraryError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>except nacl.exceptions.BadSignatureError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>securesystemslib._vendor.ed25519.ed25519.checkvalid(signature,<EOL>data, public)<EOL>valid_signature = True<EOL><DEDENT>except Exception as e:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>else: <EOL><INDENT>message = '<STR_LIT>' + repr(scheme) + '<STR_LIT>' +'<STR_LIT>' + repr(_SUPPORTED_ED25519_SIGNING_SCHEMES) + '<STR_LIT:.>'<EOL>raise securesystemslib.exceptions.UnsupportedAlgorithmError(message)<EOL><DEDENT>return valid_signature<EOL>
<Purpose>
  Determine whether the private key corresponding to 'public_key' produced
  'signature'.  verify_signature() will use the public key, the 'scheme' and
  'sig', and 'data' arguments to complete the verification.

  >>> public, private = generate_public_and_private()
  >>> data = b'The quick brown fox jumps over the lazy dog'
  >>> scheme = 'ed25519'
  >>> signature, scheme = \
      create_signature(public, private, data, scheme)
  >>> verify_signature(public, scheme, signature, data, use_pynacl=False)
  True
  >>> verify_signature(public, scheme, signature, data, use_pynacl=True)
  True
  >>> bad_data = b'The sly brown fox jumps over the lazy dog'
  >>> bad_signature, scheme = \
      create_signature(public, private, bad_data, scheme)
  >>> verify_signature(public, scheme, bad_signature, data, use_pynacl=False)
  False

<Arguments>
  public_key:
    The public key is a 32-byte string.

  scheme:
    'ed25519' signature scheme used by either the pure python
    implementation (i.e., ed25519.py) or PyNacl (i.e., 'nacl').

  signature:
    The signature is a 64-byte string.

  data:
    Data object used by securesystemslib.ed25519_keys.create_signature() to
    generate 'signature'.  'data' is needed here to verify the signature.

  use_pynacl:
    True, if the ed25519 signature should be verified by PyNaCl.  False,
    if the signature should be verified with the pure Python implementation
    of ed25519 (slower).

<Exceptions>
  securesystemslib.exceptions.UnsupportedAlgorithmError.  Raised if the
  signature scheme 'scheme' is not one supported by
  securesystemslib.ed25519_keys.create_signature().

  securesystemslib.exceptions.FormatError. Raised if the arguments are
  improperly formatted.

<Side Effects>
  securesystemslib._vendor.ed25519.ed25519.checkvalid() called to do the
  actual verification.  nacl.signing.VerifyKey.verify() called if
  'use_pynacl' is True.

<Returns>
  Boolean.  True if the signature is valid, False otherwise.