utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JwtKey = []byte("secret_key")

Functions

func DecryptAddress

func DecryptAddress(encryptedAddress models.EncryptedAddress, key []byte) (models.RawAddress, error)

DecryptAddress decrypts the address fields

func DecryptField

func DecryptField(encryptedField models.EncryptedField, key []byte) (string, error)

DecryptField decrypts a given ciphertext using AES-GCM

func EncryptAddress

func EncryptAddress(address models.RawAddress, key []byte) (models.EncryptedAddress, error)

EncryptAddress encrypts the address fields

func EncryptField

func EncryptField(plaintext string, key []byte) (models.EncryptedField, error)

EncryptField encrypts a given plaintext using AES-GCM

func GenerateHMAC

func GenerateHMAC(message, secret string) string

GenerateHMAC generates an HMAC-SHA256 hash for the given message and secret

func GenerateJWT

func GenerateJWT(userID string) (string, error)

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString generates a secure random string of the specified length

func GetClientIDFromContext

func GetClientIDFromContext(c *gin.Context) (string, error)

func HashAPIKey

func HashAPIKey(apiKey string) string

HashAPIKey hashes the given API key using SHA-256

func HashPassword

func HashPassword(password string) string

HashPassword hashes the given password using SHA-256

Types

type Claims

type Claims struct {
	UserID string `json:"cockpit_user_id"`
	jwt.StandardClaims
}

type KMSUploader

type KMSUploader struct {
	Client interfaces.KMSClient
	KeyID  string // KMS Key ID (ARN or alias) used for generating data keys
}

func NewKMSUploader

func NewKMSUploader(region, accessKey, secretAccessKey, keyID string) (*KMSUploader, error)

func (*KMSUploader) DecryptData

func (k *KMSUploader) DecryptData(ctx context.Context, encrypted []byte) ([]byte, error)

func (*KMSUploader) EncryptData

func (k *KMSUploader) EncryptData(ctx context.Context, plaintext []byte) ([]byte, error)

func (*KMSUploader) GenerateDataKey

func (k *KMSUploader) GenerateDataKey(ctx context.Context) ([]byte, []byte, error)

type S3Uploader

type S3Uploader struct {
	Client     *s3.Client
	BucketName string
}

func NewS3Uploader

func NewS3Uploader(bucketName string, region string, accessKey string, secretAccessKey string) (*S3Uploader, error)

func (*S3Uploader) DownloadFile

func (u *S3Uploader) DownloadFile(ctx context.Context, objectKey string) (*s3.GetObjectOutput, error)

This function is for testing purposes only

func (*S3Uploader) UploadFile

func (u *S3Uploader) UploadFile(ctx context.Context, file multipart.File, fileName string, mimeType string, kmsUploader interfaces.KMSUploader) (string, error)

Jump to

Keyboard shortcuts

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