utils

package
v0.0.0-...-2496799 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeRSAPrivateKey

func DecodeRSAPrivateKey(data []byte) (*rsa.PrivateKey, error)

DecodeRSAPrivateKey decodes a PEM PKCS1 private key into a rsa.PrivateKey. NOTE: Public Key is automatically derived from the private key.

func DecodeRSAPublicKey

func DecodeRSAPublicKey(data []byte) (*rsa.PublicKey, error)

DecodeRSAPublicKey decodes a PEM PKCS1 public key into a rsa.PublicKey.

func ExtractBearerToken

func ExtractBearerToken(r *http.Request) (string, error)

ExtractBearerToken obtains the authentication token from a request using the "Bearer" authorization scheme. 'Authorization: Bearer {token}'

func GenerateSHA256

func GenerateSHA256(s string) string

GenerateSHA256 generates the Base64 URL Encoded SHA-256 hash of a given string.

func GenerateSHA256NoPadding

func GenerateSHA256NoPadding(s string) string

GenerateSHA256NoPadding generates the Base64 URL Encoded SHA-256 hash of a given string with no padding.

func GetAuthenticatedUserFromContext

func GetAuthenticatedUserFromContext(ctx context.Context) (string, bool)

GetAuthenticatedUserFromContext retrieves the nickname of the user who performs the operation from the context.

func LoadRSAKeyFromFile

func LoadRSAKeyFromFile(privateKeyPath, publicKeyPath string) (*rsa.PrivateKey, error)

LoadRSAKeyFromFile reads a PEM PKCS1 key pair (private and public key) into a rsa.PrivateKey with the PublicKey properly set to the given one, instead of the default deriving from the private key.

func LoadRSAPrivateKeyFromFile

func LoadRSAPrivateKeyFromFile(path string) (*rsa.PrivateKey, error)

LoadRSAPrivateKeyFromFile reads a PEM PKCS1 private key file into a rsa.PrivateKey. NOTE: Public Key is automatically derived from the private key.

func LoadRSAPublicKeyFromFile

func LoadRSAPublicKeyFromFile(path string) (*rsa.PublicKey, error)

LoadRSAPublicKeyFromFile reads a PEM PKCS1 public key file into a rsa.PublicKey.

func RandString

func RandString(length int) string

RandString generates a random string of the given length using alphanumeric characters.

func RandStringWithCharset

func RandStringWithCharset(length int, charset string) string

RandStringWithCharset generates a random string of the given length using characters in the given charset.

func SetAuthenticatedUserInContext

func SetAuthenticatedUserInContext(ctx context.Context, userID string) context.Context

SetAuthenticatedUserInContext stores the userID of the user who performs a operation in the context.

func ValidateStruct

func ValidateStruct(v interface{}) error

ValidateStruct validates the given struct based on the struct tags added to the fields. If some field of the struct doesn't fulfill the validation requirements an error is returned.

Types

type MissingAuthenticationToken

type MissingAuthenticationToken struct{}

MissingAuthenticationToken is the error returned when an authentication token is not properly present in the HTTP request.

func (*MissingAuthenticationToken) Error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL