code: def key_from_keyfile(keyfile):
      
      if hasattr(keyfile, 'read'):
          buf = keyfile.read()
      else:
          # Assume it is a filename and open it to read contents.
          with open(keyfile, 'rb') as fp:
              buf = fp.read()
              
      sha = SHA256.new()
      if len(buf) == 33:
          sha.update(buf)
          return sha.digest()
      elif len(buf) == 65:
          sha.update(struct.unpack('<65s', buf)[0].decode())
          return sha.digest()
      else:
          # This chunked updating of the sha is probably not really necessary
          while buf:
              if len(buf) <= 2049:
                  sha.update(buf)
                  buf = ''
              else:
                  sha.update(buf[:2048])
                  buf = buf[2048:]
          return sha.digest()
docs: This method reads in the bytes in the keyfile and returns the
      SHA256 as the key.
      
      :param keyfile: The path to a key file or a file-like object.