docs: add missing documentation to functions

This commit is contained in:
Juan Pablo Villafáñez
2024-04-17 15:54:51 +02:00
parent f7671e8d19
commit 57b50c8587
11 changed files with 73 additions and 0 deletions
@@ -2,6 +2,7 @@ package middleware
import "github.com/golang-jwt/jwt/v4"
// Claims contains the jwt registered claims plus the used WOPI context
type Claims struct {
WopiContext WopiContext `json:"WopiContext"`
jwt.RegisteredClaims
@@ -9,6 +9,9 @@ import (
"io"
)
// keyPadding will add the required zero padding to the provided key.
// The resulting key will have a length of either 16, 24 or 32 bytes.
// If the key has more than 32 bytes, only the first 32 bytes will be returned.
func keyPadding(key []byte) []byte {
switch length := len(key); {
case length < 16:
@@ -29,6 +32,9 @@ func keyPadding(key []byte) []byte {
return []byte{}
}
// EncryptAES encrypts the provided plainText using the provided key.
// AES CFB will be used as cryptographic method.
// Use DecryptAES to decrypt the resulting string
func EncryptAES(key []byte, plainText string) (string, error) {
src := []byte(plainText)
@@ -49,6 +55,9 @@ func EncryptAES(key []byte, plainText string) (string, error) {
return base64.URLEncoding.EncodeToString(cipherText), nil
}
// DecryptAES decrypts the provided string using the provided key.
// The provided string must have been encrypted with AES CFB.
// This method will decrypt the result from the EncryptAES method
func DecryptAES(key []byte, securemess string) (string, error) {
cipherText, err := base64.URLEncoding.DecodeString(securemess)
if err != nil {
@@ -21,6 +21,7 @@ const (
wopiContextKey key = iota
)
// WopiContext wraps all the information we need for WOPI
type WopiContext struct {
AccessToken string
FileReference providerv1beta1.Reference
@@ -30,6 +31,17 @@ type WopiContext struct {
ViewAppUrl string
}
// WopiContextAuthMiddleware will prepare an HTTP handler to be used as
// middleware. The handler will create a WopiContext by parsing the
// access_token (which must be provided as part of the URL query).
// The access_token is required.
//
// This middleware will add the following to the request's context:
// * The access token as metadata for outgoing requests (for the
// authentication against the CS3 API, the "x-access-token" header).
// * The created WopiContext for the request
// * A contextual zerologger containing information about the request
// and the WopiContext
func WopiContextAuthMiddleware(jwtSecret string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
accessToken := r.URL.Query().Get("access_token")