Documentation
¶
Overview ¶
Package middleware provides HTTP middleware for automatic STMF decryption.
Index ¶
- Constants
- func GetFormData(r *http.Request) *stmf.FormData
- func GetMetadata(r *http.Request) map[string]string
- func HasSTMFPayload(r *http.Request, fieldName string) bool
- func Middleware(cfg Config) func(http.Handler) http.Handler
- func Simple(privateKey []byte) func(http.Handler) http.Handler
- func SimpleBase64(privateKeyB64 string) (func(http.Handler) http.Handler, error)
- type Config
Constants ¶
View Source
const ( // FormDataKey is the context key for the decrypted FormData FormDataKey contextKey = "stmf_form_data" // MetadataKey is the context key for the form metadata MetadataKey contextKey = "stmf_metadata" )
Variables ¶
This section is empty.
Functions ¶
func GetFormData ¶
GetFormData retrieves the decrypted FormData from the request context
func GetMetadata ¶
GetMetadata retrieves the form metadata from the request context
func HasSTMFPayload ¶
HasSTMFPayload checks if the request contains a STMF payload
func Middleware ¶
Middleware creates an HTTP middleware that decrypts STMF payloads. It looks for the STMF payload in the configured field name, decrypts it, and populates r.Form with the decrypted fields.
Types ¶
type Config ¶
type Config struct {
// PrivateKey is the server's X25519 private key (32 bytes)
PrivateKey []byte
// FieldName is the form field name containing the STMF payload
// Defaults to "_stmf_payload" if empty
FieldName string
// OnError is called when decryption fails
// If nil, returns 400 Bad Request
OnError func(w http.ResponseWriter, r *http.Request, err error)
// OnMissingPayload is called when the STMF field is not present
// If nil, the request passes through unchanged
OnMissingPayload func(w http.ResponseWriter, r *http.Request)
// PopulateForm controls whether decrypted fields are added to r.Form
// Defaults to true
PopulateForm *bool
}
Config holds the middleware configuration
func DefaultConfig ¶
DefaultConfig returns a Config with default values
Click to show internal directories.
Click to hide internal directories.