def format_keyval_to_metadata(keytype, scheme, key_value, private=False):
<EOL>securesystemslib.formats.KEYTYPE_SCHEMA.check_match(keytype)<EOL>securesystemslib.formats.SCHEME_SCHEMA.check_match(scheme)<EOL>securesystemslib.formats.KEYVAL_SCHEMA.check_match(key_value)<EOL>if private is True:<EOL><INDENT>if '<STR_LIT>' not in key_value:<EOL><INDENT>raise securesystemslib.exceptions.FormatError('<STR_LIT>'<EOL>'<STR_LIT>' + repr(key_value))<EOL><DEDENT>else:<EOL><INDENT>return {'<STR_LIT>': keytype, '<STR_LIT>': scheme, '<STR_LIT>': key_value}<EOL><DEDENT><DEDENT>else:<EOL><INDENT>public_key_value = {'<STR_LIT>': key_value['<STR_LIT>']}<EOL>return {'<STR_LIT>': keytype,<EOL>'<STR_LIT>': scheme,<EOL>'<STR_LIT>': securesystemslib.settings.HASH_ALGORITHMS,<EOL>'<STR_LIT>': public_key_value}<EOL><DEDENT>
<Purpose>
  Return a dictionary conformant to 'securesystemslib.formats.KEY_SCHEMA'.
  If 'private' is True, include the private key.  The dictionary
  returned has the form:

  {'keytype': keytype,
   'scheme' : scheme,
   'keyval': {'public': '...',
              'private': '...'}}

  or if 'private' is False:

  {'keytype': keytype,
   'scheme': scheme,
   'keyval': {'public': '...',
              'private': ''}}

  >>> ed25519_key = generate_ed25519_key()
  >>> key_val = ed25519_key['keyval']
  >>> keytype = ed25519_key['keytype']
  >>> scheme = ed25519_key['scheme']
  >>> ed25519_metadata = \
  format_keyval_to_metadata(keytype, scheme, key_val, private=True)
  >>> securesystemslib.formats.KEY_SCHEMA.matches(ed25519_metadata)
  True

<Arguments>
  key_type:
    The 'rsa' or 'ed25519' strings.

  scheme:
    The signature scheme used by the key.

  key_value:
    A dictionary containing a private and public keys.
    'key_value' is of the form:

    {'public': '...',
     'private': '...'}},

    conformant to 'securesystemslib.formats.KEYVAL_SCHEMA'.

  private:
    Indicates if the private key should be included in the dictionary
    returned.

<Exceptions>
  securesystemslib.exceptions.FormatError, if 'key_value' does not conform to
  'securesystemslib.formats.KEYVAL_SCHEMA', or if the private key is not
  present in 'key_value' if requested by the caller via 'private'.

<Side Effects>
  None.

<Returns>
  A 'securesystemslib.formats.KEY_SCHEMA' dictionary.