| 1 | package mech |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | |
| 6 | "github.com/mesos/mesos-go/api/v0/auth/callback" |
| 7 | ) |
| 8 | |
| 9 | var ( |
| 10 | IllegalStateErr = errors.New("illegal mechanism state") |
| 11 | ) |
| 12 | |
| 13 | type Interface interface { |
| 14 | Handler() callback.Handler |
| 15 | Discard() // clean up resources or sensitive information; idempotent |
| 16 | } |
| 17 | |
| 18 | // return a mechanism and it's initialization step (may be a noop that returns |
| 19 | // a nil data blob and handle to the first "real" challenge step). |
| 20 | type Factory func(h callback.Handler) (Interface, StepFunc, error) |
| 21 | |
| 22 | // StepFunc implementations should never return a nil StepFunc result. This |
| 23 | // helps keep the logic in the SASL authticatee simpler: step functions are |
| 24 | // never nil. Mechanisms that end up an error state (for example, some decoding |
| 25 | // logic fails...) should return a StepFunc that represents an error state. |
| 26 | // Some mechanisms may be able to recover from such. |
| 27 | type StepFunc func(m Interface, data []byte) (StepFunc, []byte, error) |
| 28 | |
| 29 | // reflects an unrecoverable, illegal mechanism state; always returns IllegalState |
| 30 | // as the next step along with an IllegalStateErr |
| 31 | func IllegalState(m Interface, data []byte) (StepFunc, []byte, error) { |
| 32 | return IllegalState, nil, IllegalStateErr |
| 33 | } |