func HandleKeyRequests() func(*Server) {
	return func(srv *Server) {
		keymux := srv.mux.PathPrefix("/_matrix/key/v2").Subrouter()
		keyFn := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			k := gomatrixserverlib.ServerKeys{}
			k.ServerName = gomatrixserverlib.ServerName(srv.ServerName)
			publicKey := srv.Priv.Public().(ed25519.PublicKey)
			k.VerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.VerifyKey{
				srv.KeyID: {
					Key: gomatrixserverlib.Base64Bytes(publicKey),
				},
			}
			k.OldVerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.OldVerifyKey{}
			k.ValidUntilTS = gomatrixserverlib.AsTimestamp(time.Now().Add(24 * time.Hour))
			toSign, err := json.Marshal(k.ServerKeyFields)
			if err != nil {
				w.WriteHeader(500)
				w.Write([]byte("complement: HandleKeyRequests cannot marshal serverkeyfields: " + err.Error()))
				return
			}

			k.Raw, err = gomatrixserverlib.SignJSON(
				string(srv.ServerName), srv.KeyID, srv.Priv, toSign,
			)
			if err != nil {
				w.WriteHeader(500)
				w.Write([]byte("complement: HandleKeyRequests cannot sign json: " + err.Error()))
				return
			}
			w.WriteHeader(200)
			w.Write(k.Raw)
		})

		keymux.Handle("/server", keyFn).Methods("GET")
		keymux.Handle("/server/", keyFn).Methods("GET")
		keymux.Handle("/server/{keyID}", keyFn).Methods("GET")
	}
}
// HandleKeyRequests is an option which will process GET /_matrix/key/v2/server requests universally when requested.
HandleKeyRequests is an option which will process GET /_matrix/key/v2/server requests universally when requested.
// HandleKeyRequests is an option which will process GET / _matrix / key / v2 / server requests universally when requested .
func HandleKeyRequests() func(*Server) {
	return func(srv *Server) {
		keymux := srv.mux.PathPrefix("/_matrix/key/v2").Subrouter()
		keyFn := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			k := gomatrixserverlib.ServerKeys{}
			k.ServerName = gomatrixserverlib.ServerName(srv.ServerName)
			publicKey := srv.Priv.Public().(ed25519.PublicKey)
			k.VerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.VerifyKey{
				srv.KeyID: {
					Key: gomatrixserverlib.Base64Bytes(publicKey),
				},
			}
			k.OldVerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.OldVerifyKey{}
			k.ValidUntilTS = gomatrixserverlib.AsTimestamp(time.Now().Add(24 * time.Hour))
			toSign, err := json.Marshal(k.ServerKeyFields)
			if err != nil {
				w.WriteHeader(500)
				w.Write([]byte("complement: HandleKeyRequests cannot marshal serverkeyfields: " + err.Error()))
				return
			}
			k.Raw, err = gomatrixserverlib.SignJSON(
				string(srv.ServerName), srv.KeyID, srv.Priv, toSign,
			)
			if err != nil {
				w.WriteHeader(500)
				w.Write([]byte("complement: HandleKeyRequests cannot sign json: " + err.Error()))
				return
			}
			w.WriteHeader(200)
			w.Write(k.Raw)
		})
		keymux.Handle("/server", keyFn).Methods("GET")
		keymux.Handle("/server/", keyFn).Methods("GET")
		keymux.Handle("/server/{keyID}", keyFn).Methods("GET")
	}
}
func HandleKeyRequests ( ) func ( * Server ) { return func ( srv * Server ) { keymux := srv . mux . PathPrefix ( " " ) . Subrouter ( ) keyFn := http . HandlerFunc ( func ( w http . ResponseWriter , req * http . Request ) { k := gomatrixserverlib . ServerKeys { } k . ServerName = gomatrixserverlib . ServerName ( srv . ServerName ) publicKey := srv . Priv . Public ( ) . ( ed25519 . PublicKey ) k . VerifyKeys = map [ gomatrixserverlib . KeyID ] gomatrixserverlib . VerifyKey { srv . KeyID : { Key : gomatrixserverlib . Base64Bytes ( publicKey ) , } , } k . OldVerifyKeys = map [ gomatrixserverlib . KeyID ] gomatrixserverlib . OldVerifyKey { } k . ValidUntilTS = gomatrixserverlib . AsTimestamp ( time . Now ( ) . Add ( 24 * time . Hour ) ) toSign , err := json . Marshal ( k . ServerKeyFields ) if err != nil { w . WriteHeader ( 500 ) w . Write ( [ ] byte ( " " + err . Error ( ) ) ) return } k . Raw , err = gomatrixserverlib . SignJSON ( string ( srv . ServerName ) , srv . KeyID , srv . Priv , toSign , ) if err != nil { w . WriteHeader ( 500 ) w . Write ( [ ] byte ( " " + err . Error ( ) ) ) return } w . WriteHeader ( 200 ) w . Write ( k . Raw ) } ) keymux . Handle ( " " , keyFn ) . Methods ( " " ) keymux . Handle ( " " , keyFn ) . Methods ( " " ) keymux . Handle ( " " , keyFn ) . Methods ( " " ) } }
HandleKeyRequests is an option which will process GET /_matrix/key/v2/server requests universally when requested.
HandleKeyRequests is an option which will process GET / _matrix / key / v2 / server requests universally when requested .