code: async def add(request: web.Request) -> web.Response:
      
      body = await request.json()
      if 'key' not in body or not isinstance(body['key'], str):
          return web.json_response(
              data={'error': 'no-key', 'message': 'No "key" element in body'},
              status=400)
      pubkey = body['key']
      # Do some fairly minor sanitization; dropbear will ignore invalid keys but
      # we still don’t want to have a bunch of invalid data in there
      alg = pubkey.split()[0]
      # We don’t allow dss so this has to be rsa or ecdsa and shouldn’t start
      # with restrictions
      if alg != 'ssh-rsa' and not alg.startswith('ecdsa'):
          LOG.warning(f"weird keyfile uploaded: starts with {alg}")
          return web.json_response(
              data={'error': 'bad-key',
                    'message': f'Key starts with invalid algorithm {alg}'},
              status=400)
      if '\n' in pubkey[:-1]:
          LOG.warning(f"Newlines in keyfile that shouldn't be there")
          return web.json_response(
              data={'error': 'bad-key', 'message': f'Key has a newline'},
              status=400)
  
      if '\n' == pubkey[-1]:
          pubkey = pubkey[:-1]
  
      # This is a more or less correct key we can write
      hashval = hashlib.new('md5', pubkey.encode()).hexdigest()
      if not key_present(hashval):
          with authorized_keys('a') as ak:
              ak.write(f'{pubkey}\n')
  
      return web.json_response(
              data={'message': 'Added key {hashval}',
                    'key_md5': hashval},
              status=201)
docs: Add a public key to the authorized_keys file.
  
      POST /server/ssh_keys {"key": key string}
      -> 201 Created
  
      If the key string doesn't look like an openssh public key, rejects with 400