mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 04:07:07 +00:00
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package e2ee
|
|
|
|
import "fmt"
|
|
|
|
// Manager holds the process-wide selected E2EE backend (or none, if E2EE
|
|
// is disabled), reachable from both the xmpp and telegram packages without
|
|
// either importing the other's e2ee-specific glue.
|
|
type Manager struct {
|
|
backend Backend
|
|
}
|
|
|
|
// NewManager selects a backend by name from the registry. An empty name
|
|
// means E2EE is disabled: the returned Manager's Backend() always reports
|
|
// ok=false, and every call site is expected to treat that as "behave
|
|
// exactly as if this feature didn't exist".
|
|
func NewManager(name string) (*Manager, error) {
|
|
if name == "" {
|
|
return &Manager{}, nil
|
|
}
|
|
b, ok := Get(name)
|
|
if !ok {
|
|
return nil, fmt.Errorf("e2ee: unknown backend %q (forgot to import its package for its init() side effect?)", name)
|
|
}
|
|
return &Manager{backend: b}, nil
|
|
}
|
|
|
|
// Backend returns the selected backend. ok is false if m is nil or no
|
|
// backend was selected (E2EE disabled) - callers should treat a nil
|
|
// Manager the same as one built via NewManager("").
|
|
func (m *Manager) Backend() (backend Backend, ok bool) {
|
|
if m == nil || m.backend == nil {
|
|
return nil, false
|
|
}
|
|
return m.backend, true
|
|
}
|