You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jwk: RegisterKeyImporter takes KeyImporter, not a typed function (#2152)
* jwk: RegisterKeyImporter takes KeyImporter, not a typed function
* jwk: collapse KeyImportFunc to a single generic name
* jwk: KeyImporter generic interface, T inferable at registration
* jwk: cover struct-shaped KeyImporter[T] dispatch path
Implementation: `RegisterKeyImporter[T any](fn func(T) (Key, error))` uses `reflect.TypeFor[T]()` to derive the map key at registration time. The runtime dispatch in `Import()` still uses `reflect.TypeOf(raw)` — this is unavoidable since the input type is only known at call time.
32
+
Implementation: `KeyImporter[T any]` is a generic interface whose `Import(raw T) (Key, error)` method is itself typed; `KeyImportFunc[T any]` is a `func(T) (Key, error)` that satisfies it. `RegisterKeyImporter[T any](ki KeyImporter[T]) error` uses `reflect.TypeFor[T]()` to derive the map key at registration time and stores a closure that re-types `any` → T at dispatch. The runtime lookup in `Import()` still keys by `reflect.TypeOf(raw)`.
32
33
33
-
Callers holding a full `KeyImporter` value can register it through the same entry point by passing `imp.Import`as the function: `RegisterKeyImporter[T](imp.Import)`.
34
+
The earlier v4.0.0 release shipped `RegisterKeyImporter[T](fn func(T) (Key, error))` — accepting a typed function rather than a `KeyImporter`, with the public `KeyImporter` interface and `KeyImportFunc` adapter exposed but never reachable from registration. The current shape restores the interface as the canonical registration value, makes the interface generic so type-parameter inference covers the registration call, and makes `KeyImportFunc[T]` a generic typed-function adapter that satisfies it.
returnfmt.Errorf(`jwk.RegisterKeyImporter: an importer for %s is already registered; call jwk.UnregisterKeyImporter[%s]() first if you need to replace it`, t, t)
105
119
}
106
-
keyImporters[t] =&keyImportAdapter[T]{fn: fn}
120
+
keyImporters[t] =func(rawany) (Key, error) {
121
+
// Safe: dispatch in convertRawKey keys this entry by
122
+
// reflect.TypeOf(raw) matching reflect.TypeFor[T](), so the
0 commit comments