Documentation
¶
Index ¶
- Constants
- func CalculateMd5(filePath string) (string, error)
- func EnvDefaultFunc(k string, defaultValue string) string
- func EnvDefaultFuncBool(k string, defaultValue bool) bool
- func EnvDefaultFuncInt64Value(k string, defaultValue types.Int64) types.Int64
- func EnvDefaultFuncStringList(k string, defaultValue []string) []string
- func MultiEnvDefaultFunc(ks []string, defaultValue string) string
- func ParseCertificateData(ctx context.Context, certData []byte, password []byte) ([]*x509.Certificate, crypto.PrivateKey, error)
Constants ¶
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 ¶
CalculateMd5 calculates the MD5 checksum of a file.
func EnvDefaultFunc ¶
EnvDefaultFunc is a helper function that returns the value of the given environment variable, if one exists, or the default value otherwise.
func EnvDefaultFuncBool ¶
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 ¶
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 ¶
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 ¶
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.