common

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlphanumericChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	NumericChars      = "0123456789"

	SessionTokenRegex = "[" + AlphanumericChars + "]{20}"

	EncryptedSchemePrivateKeyHeader = "ENCRYPTED IRMA SCHEME PRIVATE KEY"
)

Variables

View Source
var ForceHTTPS = true

ForceHTTPS disables HTTP forcing in irma.HTTPTransport for all instances, regardless of the instance's ForceHTTPS member. Only for use in unit tests.

View Source
var HTTPClient = &http.Client{}

HTTPClient is the shared HTTP client used across irmago for ad-hoc outbound requests (EUDI configuration, OpenID4VCI/OpenID4VP, SD-JWT VC type-metadata fetching and remote image downloads). Centralizing it gives a single place to configure outbound client behaviour instead of scattering per-call http.Client values with diverging settings.

It uses http.DefaultTransport (the shared default connection pool) and sets no client-level Timeout on purpose: a Client.Timeout keeps running while the response body is read and interrupts it (see issue #606). Callers bound their requests with a per-request context deadline instead.

The dedicated clients in irma/transport.go (retryable, cookie-jar and SIGPIPE-aware transport) and internal/test are intentionally not replaced by this one: they carry purpose-specific configuration rather than being ad-hoc default clients.

View Source
var Logger *logrus.Logger
View Source
var SchemeFilenames = []string{"description.xml", "description.json"}

Functions

func AssertPathExists

func AssertPathExists(paths ...string) error

AssertPathExists returns nil only if it has been successfully verified that all specified paths exists.

func AssertPathNotExists

func AssertPathNotExists(paths ...string) error

func Base64Decode

func Base64Decode(b []byte) ([]byte, error)

Base64Decode decodes the specified bytes as any of the Base64 dialects: standard encoding (+, /) and URL encoding (-, _), with or without padding.

func Close added in v0.8.0

func Close(o io.Closer)

Close is a helper for absorbing errors in the `defer x.Close()` pattern

func CopyDirectory

func CopyDirectory(src, dest string) error

func EnsureDirectoryExists

func EnsureDirectoryExists(path string) error

func EnsureFileExists added in v1.0.0

func EnsureFileExists(path string) error

func IsIrmaconfDir added in v0.6.0

func IsIrmaconfDir(dir string) (bool, error)

func IsScheme added in v0.6.0

func IsScheme(dir string, expectSignature bool) (bool, error)

func IsTempSchemeDir added in v0.11.2

func IsTempSchemeDir(dirname string) bool

func IterateSubfolders

func IterateSubfolders(path string, handler func(string, os.FileInfo) error) error

IterateSubfolders iterates over the subfolders of the specified path, calling the specified handler each time. If anything goes wrong, or if the caller returns a non-nil error, an error is immediately returned.

func MarshalSchemePrivateKeyWithPassphrase added in v0.17.0

func MarshalSchemePrivateKeyWithPassphrase(key *ecdsa.PrivateKey, passphrase []byte) ([]byte, error)

func NewPairingCode added in v0.8.0

func NewPairingCode() string

func NewRandomString added in v0.8.0

func NewRandomString(count int, characterSet string) string

func NewSessionToken

func NewSessionToken() string

func ParseLDContext added in v0.9.0

func ParseLDContext(bts []byte) (string, error)

func ParseNestedLDContext added in v0.9.0

func ParseNestedLDContext(bts []byte) (string, error)

func ParseSchemePrivateKeyWithPassphrase added in v0.17.0

func ParseSchemePrivateKeyWithPassphrase(bts []byte, passphrase []byte) (*ecdsa.PrivateKey, error)

func PathExists

func PathExists(path string) (bool, error)

PathExists checks if the specified path exists.

func RandomBigInt

func RandomBigInt(limit *big.Int) *big.Int

func ReadKey

func ReadKey(key, path string) ([]byte, error)

ReadKey returns either the content of the file specified at path, if it exists, or []byte(key) otherwise. It is an error to specify both or none arguments, or specify an empty or unreadable file. If there is no error then the return []byte is non-empty.

func SanitizeForLog added in v1.1.0

func SanitizeForLog(s string) string

SanitizeForLog replaces CR and LF characters in s to prevent log injection.

func SaveFile

func SaveFile(fpath string, content []byte) (err error)

SaveFile saves the file contents at the specified path atomically: - first save the content in a temp file with a random filename in the same dir - then rename the temp file to the specified filepath, overwriting the old file

func SchemeFilename added in v0.6.0

func SchemeFilename(dir string) (string, error)

func SchemeInfo added in v0.6.0

func SchemeInfo(filename string, bts []byte) (string, string, error)

func Stat

func Stat(path string) (os.FileInfo, bool, error)

func Unmarshal added in v0.6.0

func Unmarshal(filename string, bts []byte, dest any) error

func ValidateSchemeID added in v0.11.2

func ValidateSchemeID(id string) error

func WalkDir

func WalkDir(path string, handler func(string, os.FileInfo) error) error

WalkDir recursively walks the file tree rooted at path, following symlinks (unlike filepath.Walk). Avoiding loops is the responsibility of the caller.

Types

type SSECtx

type SSECtx struct {
	Component, Arg string
}

Jump to

Keyboard shortcuts

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