file

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmptyFilePerms      fs.FileMode = 0000
	CertFilePerms       fs.FileMode = 0600
	CertFilePermsMask   fs.FileMode = 0133
	KeyFilePerms        fs.FileMode = 0600
	PubKeyFilePerms     fs.FileMode = 0644
	KeyFilePermsMask    fs.FileMode = 0177
	PubKeyFilePermsMask fs.FileMode = 0133
)

Verifying and setting file permissions for public/private keys and certificates use the following file mode masks. The *Perms modes are the desired permissions, while the *PermsMask consts are such that perms && mask should always be 0. The mask is only needed because _technically_ I suppose you could make a public key mode 600 or something if you really wanted.

View Source
const (
	SecretFilePermsInclude fs.FileMode = 0600
	SecretFilePermsExclude fs.FileMode = 0177
)

Variables

View Source
var (
	ErrFileNone = fileOptionError("vale of File path is not set")
)

Functions

This section is empty.

Types

type Cert

type Cert struct {
	// contains filtered or unexported fields
}

Cert wraps an optional path string and provides extra methods for reading, decoding, and writing pem files containing CERTIFICATE blocks.

func NoCert

func NoCert() Cert

func SomeCert

func SomeCert(path string) (Cert, error)

func (Cert) FilePermsValid

func (o Cert) FilePermsValid() (bool, error)

func (Cert) ReadBlocks

func (o Cert) ReadBlocks() (blocks []*pem.Block, err error)

func (Cert) ReadCerts

func (o Cert) ReadCerts() (certs []*x509.Certificate, err error)

func (*Cert) Replace

func (o *Cert) Replace(path string) optional.Optional[string]

Override the inner Replace() method to convert path to absolute paths if possible

func (*Cert) Set

func (o *Cert) Set(str string) error

func (Cert) SetFilePerms

func (o Cert) SetFilePerms() error

func (Cert) String

func (o Cert) String() string

func (Cert) Type

func (o Cert) Type() string

func (*Cert) UnmarshalText

func (o *Cert) UnmarshalText(text []byte) error

func (Cert) WriteBlocks

func (o Cert) WriteBlocks(blocks []*pem.Block) error

func (Cert) WriteCerts

func (o Cert) WriteCerts(certs []*x509.Certificate) error

type File

type File struct {
	optional.Str
}

func NoFile

func NoFile() File

func SomeFile

func SomeFile(path string) File

func (File) Abs

func (o File) Abs() (opt File, err error)

func (File) Create

func (o File) Create() (*os.File, error)

func (File) Exists

func (o File) Exists() bool

func (File) FilePermsValid

func (o File) FilePermsValid(include fs.FileMode, exclude fs.FileMode) (bool, error)

func (File) Match

func (o File) Match(probe string) bool

Overrides Option.Match to account for relative paths potentially being different strings but representing the same file.

func (File) Open

func (o File) Open() (*os.File, error)

func (File) OpenFile added in v0.2.0

func (o File) OpenFile(flag int, perm os.FileMode) (*os.File, error)

func (File) ReadFile added in v0.2.0

func (o File) ReadFile() (contents optional.Str, ok bool)

func (File) Remove added in v0.2.0

func (o File) Remove() error

func (File) SetFilePerms

func (o File) SetFilePerms(mode fs.FileMode) error

func (File) Stat

func (o File) Stat() (stat fs.FileInfo, err error)

func (File) String

func (o File) String() string

Override the String() method from the inner Str just so we return the correct None[Type] string.

func (File) Type

func (o File) Type() string

Override the Type() method from the inner Str. Part of the flag.Value interface.

func (File) WriteFile added in v0.2.0

func (o File) WriteFile(data []byte, perm os.FileMode) (err error)

type FileOptionError added in v0.2.0

type FileOptionError struct {
	// contains filtered or unexported fields
}

func (FileOptionError) Error added in v0.2.0

func (e FileOptionError) Error() string

type PrivateKey

type PrivateKey struct {
	// contains filtered or unexported fields
}

PubKey wraps an optional path string and provides extra methods for reading, decoding, and writing pem files containing "* PRIVATE KEY" blocks.

func NoPrivateKey

func NoPrivateKey() PrivateKey

func SomePrivateKey

func SomePrivateKey(path string) (PrivateKey, error)

func (PrivateKey) FilePermsValid

func (o PrivateKey) FilePermsValid() (bool, error)

func (PrivateKey) ReadBlocks

func (o PrivateKey) ReadBlocks() (blocks []*pem.Block, err error)

func (PrivateKey) ReadCert

func (o PrivateKey) ReadCert(in Cert) (cert tls.Certificate, err error)

ReadCert accepts a Cert struct and returns a tls.Certificate for the keypair if both Optionals are Some. This is going to be the most used case for anyone loading

func (PrivateKey) ReadPrivateKey

func (o PrivateKey) ReadPrivateKey() (key any, err error)

ReadPrivateKey will return the first private key found in the given filepath or error. This may return an *rsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey (Note: that is not a pointer), or *ecdh.PrivateKey, depending on the contents of the file.

func (*PrivateKey) Replace

func (o *PrivateKey) Replace(path string) optional.Optional[string]

Override the inner Replace() method to convert path to absolute paths if possible

func (*PrivateKey) Set

func (o *PrivateKey) Set(str string) error

func (PrivateKey) SetFilePerms

func (o PrivateKey) SetFilePerms() error

func (PrivateKey) String

func (o PrivateKey) String() string

func (PrivateKey) Type

func (o PrivateKey) Type() string

func (*PrivateKey) UnmarshalText

func (o *PrivateKey) UnmarshalText(text []byte) error

func (PrivateKey) WriteBlocks

func (o PrivateKey) WriteBlocks(blocks []*pem.Block) error

func (PrivateKey) WritePrivateKey

func (o PrivateKey) WritePrivateKey(key any) error

WritePrivateKey will accept any of an *rsa.PrivateKey, *dsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey (Note: a pointer), or *ecdh.PrivateKey. The key will be encoded and written to the path the PrivateKey option is set to with file permissions set appropriately.

type PubKey

type PubKey struct {
	// contains filtered or unexported fields
}

PubKey wraps an optional path string and provides extra methods for reading, decoding, and writing pem files containing "* PUBLIC KEY" blocks.

func NoPubKey

func NoPubKey() PubKey

func SomePubKey

func SomePubKey(path string) (PubKey, error)

func (PubKey) FilePermsValid

func (o PubKey) FilePermsValid() (bool, error)

func (PubKey) ReadBlocks

func (o PubKey) ReadBlocks() (blocks []*pem.Block, err error)

func (PubKey) ReadPublicKeys

func (o PubKey) ReadPublicKeys() (pub []any, err error)

ReadPublicKeys will return all public keys found in the given filepath or error. The keys may be of type *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey (Note: that is not a pointer), or *ecdh.PublicKey, depending on the contents of the file.

func (*PubKey) Replace

func (o *PubKey) Replace(path string) optional.Optional[string]

Override the inner Replace() method to convert path to absolute paths if possible

func (*PubKey) Set

func (o *PubKey) Set(str string) error

func (PubKey) SetFilePerms

func (o PubKey) SetFilePerms() error

func (PubKey) String

func (o PubKey) String() string

func (PubKey) Type

func (o PubKey) Type() string

func (*PubKey) UnmarshalText

func (o *PubKey) UnmarshalText(text []byte) error

func (PubKey) WriteBlocks

func (o PubKey) WriteBlocks(blocks []*pem.Block) error

func (PubKey) WritePublicKeys

func (o PubKey) WritePublicKeys(pubs []any) error

WritePublicKey will accept any of an *rsa.PublicKey, *dsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey (Note: a pointer), or *ecdh.PublicKey. The key will be encoded and written to the path the PubKey option is set to with file permissions set appropriately.

type SecretFile added in v0.2.2

type SecretFile struct {
	File
}

func MakeSecret added in v0.2.2

func MakeSecret(f *File) SecretFile

MakeSecret takes a pointer to an existing File and returns a SecretFile then clears the original so that it cannot be used and accidentally expose the sercret.

func NoSecretFile added in v0.2.2

func NoSecretFile() SecretFile

func SomeSecretFile added in v0.2.2

func SomeSecretFile(path string) SecretFile

func (SecretFile) Abs added in v0.2.2

func (o SecretFile) Abs() (opt SecretFile, err error)

func (SecretFile) FilePermsValid added in v0.2.2

func (o SecretFile) FilePermsValid() (bool, error)

func (SecretFile) OpenFile added in v0.2.2

func (o SecretFile) OpenFile(flag int) (*os.File, error)

func (SecretFile) ReadFile added in v0.2.2

func (o SecretFile) ReadFile() (secret optional.Secret, ok bool)

func (SecretFile) String added in v0.2.2

func (o SecretFile) String() string

Override the String() method from the inner value just so we return the correct None[Type] string.

func (SecretFile) Type added in v0.2.2

func (o SecretFile) Type() string

Override the Type() method from the inner value. Part of the flag.Value interface.

Jump to

Keyboard shortcuts

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