files

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package files provides utilities for handling and validating files like PEM, JWT, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePem

func DecodePem(pemData []byte, filePath string, returnParsed bool) (any, error)

DecodePem decodes and parses PEM data, returning the parsed cryptographic object For validation only (when returnParsed is false), returns nil on success For loading (when returnParsed is true), returns the parsed key/certificate

func DeleteFile

func DeleteFile(path string, file string) error

func EncodePem

func EncodePem(publicKeyRaw ed25519.PublicKey, privateKeyRaw ed25519.PrivateKey, certificateRaw *x509.Certificate) (publicKey []byte, privateKey []byte, certificate []byte, err error)

EncodePem encodes an ed25519 public key, ed25519 private key, and/or x509 certificate into PEM format. Note that return values are nil if corresponding input is nil.

func LoadJWT

func LoadJWT(logger *slog.Logger, path string, file string, required bool) ([]byte, error)

LoadJWT reads a JWT token from a file (first line only, trimmed). Returns nil if the file does not exist and required is false.

func LoadPEM

func LoadPEM(logger *slog.Logger, path string, file string, required bool) (any, error)

LoadPEM reads and parses a PEM file, returning the parsed cryptographic object. Returns nil if the file does not exist and required is false. Supported types: ed25519.PublicKey, ed25519.PrivateKey, *x509.Certificate

func LoadString

func LoadString(logger *slog.Logger, path string, file string, required bool) (string, error)

LoadString reads a text file and returns its contents as a trimmed string. Returns empty string if the file does not exist and required is false.

func WritePEM

func WritePEM(path string, file string, data string, mode os.FileMode) error

WritePEM writes PEM-encoded data to a file after validating it.

func WriteString

func WriteString(path string, file string, data string, mode os.FileMode) error

WriteString writes a trimmed string to a file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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