generic

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: BSD-3-Clause Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCustomEncoderIsNil = errors.New("custom encoder is nil")

Functions

func AllZero

func AllZero(s []byte) bool

AllZero checks if all bytes in a slice are zero.

func CSPRNG

func CSPRNG(n int64) ([]byte, error)

CSPRNG is a cryptographically secure pseudo-random number generator for byte slices.

func CSPRNGHex

func CSPRNGHex(n int64) (string, error)

CSPRNGHex is a CSPRNG in hex format.

func Compare

func Compare(x, y []byte) bool

func CompareString

func CompareString(x, y string) bool

func Delete

func Delete(targetPath string, cycle int) error

Secure way to delete file.

func FileWalkByName

func FileWalkByName(startPath, name string) ([]string, error)

func HWRng

func HWRng(n int64) ([]byte, error)

HWRng is a hardware random number generator.

func IsRepeatingSequence added in v0.1.1

func IsRepeatingSequence(key []byte) bool

func Overwrite

func Overwrite(targetPath string, data []byte, cycle int) error

Secure way to overwrite file.

func Rand

func Rand() io.Reader

func ReadFileContent

func ReadFileContent(path string) ([]byte, error)

func StrCnct

func StrCnct(str ...string) string

StrCnct concatenates strings into one Example: StrCnct([]string{"a", "b", "c"}...) -> "abc".

func WriteAndFlush

func WriteAndFlush(file *os.File, rnd []byte) (n int, err error)

Types

type Base32

type Base32 struct{}

func (*Base32) Decode

func (b *Base32) Decode(data string) ([]byte, error)

func (*Base32) Encode

func (b *Base32) Encode(data []byte) string

func (*Base32) GetName added in v0.1.1

func (b *Base32) GetName() string

type Base64

type Base64 struct{}

StdEncoding is the standard base64 encoding, as defined in RFC 4648.

func (*Base64) Decode

func (b *Base64) Decode(data string) ([]byte, error)

func (*Base64) Encode

func (b *Base64) Encode(data []byte) string

func (*Base64) GetName added in v0.1.1

func (b *Base64) GetName() string

type Custom added in v0.1.1

type Custom struct {
	Encoder func([]byte) string
	Decoder func(string) ([]byte, error)
}

func (*Custom) Decode added in v0.1.1

func (c *Custom) Decode(data string) ([]byte, error)

func (*Custom) Encode added in v0.1.1

func (c *Custom) Encode(data []byte) string

func (*Custom) GetName added in v0.1.1

func (c *Custom) GetName() string

type Encoder

type Encoder interface {
	Encode([]byte) string
	Decode(string) ([]byte, error)
	GetName() string
}

type Hex

type Hex struct{}

func (*Hex) Decode

func (h *Hex) Decode(data string) ([]byte, error)

func (*Hex) Encode

func (h *Hex) Encode(data []byte) string

func (*Hex) GetName added in v0.1.1

func (h *Hex) GetName() string

type ImportExport

type ImportExport interface {
	Import() error
	Export() error
}

type PKCS

type PKCS struct {
	SecretKey  ed25519.PrivateKey
	ImportData string
	ExportData string
	Encoder    Encoder
}

func (*PKCS) Export

func (e *PKCS) Export() error

struct PKCS SecretKey (ed25519.PrivateKey) -> struct PKCS ExportData (string).

func (*PKCS) Import

func (e *PKCS) Import() error

struct PKCS ImportData (string) -> struct PKCS SecretKey (ed25519.PrivateKey).

type PKIX

type PKIX struct {
	PublicKey       ed25519.PublicKey
	ImportData      string
	ExportData      string
	ExportPublicKey crypto.PublicKey
	Encoder         Encoder
}

PKIX is a generic struct for import and export Ed25519 public key One way to import: 1. ImportData (string) -> PublicKey (ed25519.PublicKey) Two ways to export: 1. PublicKey (ed25519.PublicKey) -> ExportData (string) 2. ExportPublicKey (crypto.PublicKey) -> ExportData (string).

func (*PKIX) Export

func (e *PKIX) Export() error

Two ways to export: 1. struct PKIX PublicKey (ed25519.PublicKey) -> struct PKIX ExportData (string) 2. struct PKIX ExportPublicKey (crypto.PublicKey) -> struct PKIX ExportData (string).

func (*PKIX) Import

func (e *PKIX) Import() error

struct PKIX ImportData (string) -> struct PKIX PublicKey (ed25519.PublicKey).

type PaddinglessBase32

type PaddinglessBase32 struct{}

func (*PaddinglessBase32) Decode

func (b *PaddinglessBase32) Decode(data string) ([]byte, error)

func (*PaddinglessBase32) Encode

func (b *PaddinglessBase32) Encode(data []byte) string

func (*PaddinglessBase32) GetName added in v0.1.1

func (b *PaddinglessBase32) GetName() string

type RawBase64

type RawBase64 struct{}

nolint: lll RawStdEncoding is the standard raw, unpadded base64 encoding, as defined in RFC 4648 section 3.2. This is the same as StdEncoding but omits padding characters.

func (*RawBase64) Decode

func (b *RawBase64) Decode(data string) ([]byte, error)

func (*RawBase64) Encode

func (b *RawBase64) Encode(data []byte) string

func (*RawBase64) GetName added in v0.1.1

func (b *RawBase64) GetName() string

type RawURLBase64 added in v0.1.0

type RawURLBase64 struct{}

nolint: lll RawURLEncoding is the unpadded alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names. This is the same as URLEncoding but omits padding characters.

func (*RawURLBase64) Decode added in v0.1.0

func (b *RawURLBase64) Decode(data string) ([]byte, error)

func (*RawURLBase64) Encode added in v0.1.0

func (b *RawURLBase64) Encode(data []byte) string

func (*RawURLBase64) GetName added in v0.1.1

func (b *RawURLBase64) GetName() string

type URLBase64 added in v0.1.0

type URLBase64 struct{}

URLEncoding is the alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names.

func (*URLBase64) Decode added in v0.1.0

func (b *URLBase64) Decode(data string) ([]byte, error)

func (*URLBase64) Encode added in v0.1.0

func (b *URLBase64) Encode(data []byte) string

func (*URLBase64) GetName added in v0.1.1

func (b *URLBase64) GetName() string

Jump to

Keyboard shortcuts

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