2023-04-02 18:54:36 +03:00
|
|
|
package jwt
|
|
|
|
|
2023-09-13 18:24:50 +03:00
|
|
|
import "io"
|
|
|
|
|
2023-09-15 23:33:21 +03:00
|
|
|
// Base64Encoding represents an object that can encode and decode base64. A
|
|
|
|
// common example is [encoding/base64.Encoding].
|
2023-09-14 22:25:59 +03:00
|
|
|
type Base64Encoding interface {
|
|
|
|
EncodeToString(src []byte) string
|
|
|
|
DecodeString(s string) ([]byte, error)
|
|
|
|
}
|
2023-04-02 18:54:36 +03:00
|
|
|
|
2023-09-16 14:31:27 +03:00
|
|
|
type StrictFunc[T Base64Encoding] func() T
|
|
|
|
|
2023-09-14 22:25:59 +03:00
|
|
|
type Stricter[T Base64Encoding] interface {
|
|
|
|
Strict() T
|
|
|
|
}
|
2023-04-02 18:54:36 +03:00
|
|
|
|
2023-09-16 14:31:27 +03:00
|
|
|
func DoStrict[S Base64Encoding, T Stricter[S]](x T) Base64Encoding {
|
|
|
|
return x.Strict()
|
|
|
|
}
|
|
|
|
|
2024-07-06 08:33:20 +03:00
|
|
|
// JSONMarshalFunc is a function type that allows to implement custom JSON
|
2023-09-14 22:25:59 +03:00
|
|
|
// encoding algorithms.
|
2023-04-02 18:54:36 +03:00
|
|
|
type JSONMarshalFunc func(v any) ([]byte, error)
|
|
|
|
|
2024-07-06 08:33:20 +03:00
|
|
|
// JSONUnmarshalFunc is a function type that allows to implement custom JSON
|
2023-09-14 22:25:59 +03:00
|
|
|
// unmarshal algorithms.
|
2023-04-02 18:54:36 +03:00
|
|
|
type JSONUnmarshalFunc func(data []byte, v any) error
|
2023-09-13 18:24:50 +03:00
|
|
|
|
|
|
|
type JSONDecoder interface {
|
|
|
|
UseNumber()
|
|
|
|
Decode(v any) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type JSONNewDecoderFunc[T JSONDecoder] func(r io.Reader) T
|