utils

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertifyKey

func CertifyKey(pubbytes []byte, template *x509.Certificate, caKey *rsa.PrivateKey, caCert *x509.Certificate) (*x509.Certificate, error)

CertifyKey certifies a public key using the given CA's private key and cert; The certificate template for the public key is optional

func CreateECDSAKey added in v1.1.10

func CreateECDSAKey(curve elliptic.Curve) (*ecdsa.PrivateKey, error)

CreateECDSAKey creates an elliptic curve key for the given curve

func CreateECDSATestKey

func CreateECDSATestKey(curve elliptic.Curve) ([]byte, []byte, error)

CreateECDSATestKey creates and elliptic curve key for the given curve and returns the public and private key in DER format

func CreateRSAKey

func CreateRSAKey(bits int) (*rsa.PrivateKey, error)

CreateRSAKey creates an RSA key

func CreateRSATestKey

func CreateRSATestKey(bits int, password []byte, pemencode bool) ([]byte, []byte, error)

CreateRSATestKey creates an RSA key of the given size and returns the public and private key in PEM or DER format

func CreateTestCA

func CreateTestCA() (*rsa.PrivateKey, *x509.Certificate, error)

CreateTestCA creates a root CA for testing

func FillBuffer

func FillBuffer(reader io.Reader, buffer []byte) (int, error)

FillBuffer fills the given buffer with as many bytes from the reader as possible. It returns EOF if an EOF was encountered or any other error.

func IsCertificate

func IsCertificate(data []byte) bool

IsCertificate returns true in case the given byte array represents an x.509 certificate

func IsGPGPrivateKeyRing

func IsGPGPrivateKeyRing(data []byte) bool

IsGPGPrivateKeyRing returns true in case the given byte array represents a GPG private key ring file

func IsPasswordError

func IsPasswordError(err error) bool

IsPasswordError checks whether an error is related to a missing or wrong password

func IsPkcs11PrivateKey added in v1.1.0

func IsPkcs11PrivateKey(data []byte) bool

IsPkcs11PrivateKey returns true in case the given byte array represents a pkcs11 private key

func IsPkcs11PublicKey added in v1.1.0

func IsPkcs11PublicKey(data []byte) bool

IsPkcs11PublicKey returns true in case the given byte array represents a pkcs11 public key

func IsPrivateKey

func IsPrivateKey(data []byte, password []byte) (bool, error)

IsPrivateKey returns true in case the given byte array represents a private key It returns an error if for example the password is wrong

func IsPublicKey

func IsPublicKey(data []byte) bool

IsPublicKey returns true in case the given byte array represents a public key

func NewDelayedReader

func NewDelayedReader(reader io.Reader, bufsize uint) io.Reader

NewDelayedReader wraps a io.Reader and allocates a delay buffer of bufsize bytes

func ParseCertificate

func ParseCertificate(certBytes []byte, prefix string) (*x509.Certificate, error)

ParseCertificate tries to parse a public key in DER format first and PEM format after, returning an error if the parsing failed

func ParsePrivateKey

func ParsePrivateKey(privKey, privKeyPassword []byte, prefix string) (interface{}, error)

ParsePrivateKey tries to parse a private key in DER format first and PEM format after, returning an error if the parsing failed

func ParsePublicKey

func ParsePublicKey(pubKey []byte, prefix string) (interface{}, error)

ParsePublicKey tries to parse a public key in DER format first and PEM format after, returning an error if the parsing failed

func SortDecryptionKeys

func SortDecryptionKeys(b64ItemList string) (map[string][][]byte, error)

SortDecryptionKeys parses a list of comma separated base64 entries and sorts the data into a map. Each entry in the list may be either a GPG private key ring, private key, or x.509 certificate

Types

type CommandExecuter added in v1.1.0

type CommandExecuter interface {
	Exec(string, []string, []byte) ([]byte, error)
}

first argument is the command, like cat or echo, the second is the list of args to pass to it

type DelayedReader

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

DelayedReader wraps a io.Reader and allows a client to use the Reader interface. The DelayedReader holds back some buffer to the client so that it can report any error that occurred on the Reader it wraps early to the client while it may still have held some data back.

func (*DelayedReader) Read

func (dr *DelayedReader) Read(p []byte) (int, error)

Read implements the io.Reader interface

type Runner added in v1.1.0

type Runner struct{}

func (Runner) Exec added in v1.1.0

func (r Runner) Exec(cmdName string, args []string, input []byte) ([]byte, error)

ExecuteCommand is used to execute a linux command line command and return the output of the command with an error if it exists.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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