helpers

package
v0.4.1-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GuidRegex             = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
	GuidOrEmptyValueRegex = "^(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})?$"
	UrlValidStringRegex   = "(?i)^[A-Za-z0-9-._~%/:/?=]+$"
	ApiIdRegex            = "^[0-9a-zA-Z/._]*$"
	StringRegex           = "^.*$"
	VersionRegex          = "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$"
	TimeRegex             = "^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z)$"
	BooleanRegex          = "^(true|false)$"
	TimeFormatRFC3339     = time.RFC3339
)

Variables

This section is empty.

Functions

func CalculateMd5

func CalculateMd5(filePath string) (string, error)

CalculateMd5 calculates the MD5 checksum of a file.

func EnvDefaultFunc

func EnvDefaultFunc(k string, defaultValue string) string

EnvDefaultFunc is a helper function that returns the value of the given environment variable, if one exists, or the default value otherwise.

func EnvDefaultFuncBool

func EnvDefaultFuncBool(k string, defaultValue bool) bool

EnvDefaultFuncBool is a helper function that returns the boolean value of the given environment variable, if one exists, or the default value otherwise.

func EnvDefaultFuncInt64Value

func EnvDefaultFuncInt64Value(k string, defaultValue types.Int64) types.Int64

EnvDefaultFuncInt64Value is a helper function that returns the types.Int64Value of the given environment variable, if one exists, or the default value otherwise.

func EnvDefaultFuncStringList

func EnvDefaultFuncStringList(k string, defaultValue []string) []string

EnvDefaultFuncStringList is a helper function that returns a slice of strings based on the environment variable (if set) or the provided default value. The environment variable should be a comma-separated string.

func MultiEnvDefaultFunc

func MultiEnvDefaultFunc(ks []string, defaultValue string) string

MultiEnvDefaultFunc is a helper function that returns the value of the first environment variable in the given list that returns a non-empty value. If none of the environment variables return a value, the default value is returned.

func ParseCertificateData

func ParseCertificateData(ctx context.Context, certData []byte, password []byte) ([]*x509.Certificate, crypto.PrivateKey, error)

ParseCertificateData decodes and parses PKCS#12 data, extracting certificates and a private key.

This function attempts to decode PKCS#12 data using the provided password. It extracts the certificate chain (including the end-entity certificate and any CA certificates), as well as the private key associated with the end-entity certificate.

The function performs several validations: - It checks if any certificates are present in the decoded data. - It verifies the presence of a private key. - It ensures the private key is of RSA type.

The function logs debug, error, and info messages at various stages of the process.

Parameters:

  • ctx: A context.Context for logging and potential cancellation.
  • certData: A byte slice containing the PKCS#12 data to be parsed.
  • password: A byte slice containing the password to decrypt the PKCS#12 data.

Returns:

  • []*x509.Certificate: A slice of parsed X.509 certificates, with the end-entity certificate as the first element, followed by any CA certificates.
  • crypto.PrivateKey: The private key associated with the end-entity certificate.
  • error: An error if any step of the parsing or validation process fails. This will be nil if the function executes successfully.

Possible errors:

  • Failure to parse PKCS#12 data
  • No certificates found in the PKCS#12 data
  • No private key found in the PKCS#12 data
  • Private key is not of RSA type

Usage example:

certs, privKey, err := ParseCertificateData(ctx, pkcs12Data, []byte("password"))
if err != nil {
    // Handle error
}
// Use certs and privKey as needed

Types

This section is empty.

Jump to

Keyboard shortcuts

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