47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package middleware
|
|
|
|
//
|
|
//import (
|
|
// "amuz.es/src/mercury/bootstrap"
|
|
// "amuz.es/src/mercury/endpoint/middleware2/internal"
|
|
// rmisc "amuz.es/src/mercury/endpoint/misc"
|
|
// "amuz.es/src/go/logging"
|
|
// "amuz.es/src/mercury/util/mycrypt"
|
|
// "github.com/pkg/errors"
|
|
// "github.com/valyala/fasthttp"
|
|
//)
|
|
//
|
|
//const (
|
|
// SecretBoxMiddlewareName = "secret_box"
|
|
//)
|
|
//
|
|
//type (
|
|
// SecretToolbox interface {
|
|
// Encrypt(data map[string]string) (string, error)
|
|
// Decrypt(encrypted string) (map[string]string, error)
|
|
// }
|
|
//)
|
|
//
|
|
//func SecretBoxFunc(box mycrypt.SecretBox, parentLogger logging.Logger) rmisc.SecretBoxMiddleware {
|
|
// if box == nil {
|
|
// panic(errors.New("secret box needed"))
|
|
// }
|
|
// logger := parentLogger.Named("secret_box")
|
|
// var toolBox rmisc.SecretToolbox = &internal.SecretToolboxImpl{
|
|
// EncryptWriter: box.NewEncryptWriter,
|
|
// DecryptReader: box.NewDecryptReader,
|
|
// }
|
|
// return func(next rmisc.Router) rmisc.Router {
|
|
// return func(ctx *fasthttp.RequestCtx) {
|
|
// ctx.SetUserValue(rmisc.SecretBoxContextKey, toolBox)
|
|
// logger.Info("injected secret box")
|
|
// next(ctx)
|
|
// }
|
|
// }
|
|
//
|
|
//}
|
|
//
|
|
//func NewSecretBox(sessionConfig bootstrap.SessionConfig) rmisc.RouterSecretBox {
|
|
// return mycrypt.NewSecretBox(sessionConfig.Secret())
|
|
//}
|