cli

package
v0.0.0-...-acb5644 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 8 Imported by: 0

README

Package cli

This package is the CLI implementation of gfc. The main implementation is in cli.go.

gfc subcommands

gfc is designed as a command-line program with subcommands similar to how git has git add and git commit. In gfc, a subcommand is a cryptographic algorithm. Currently, 2 are available (gfc aes and gfc rsa). Two add a new subcommand, just create a new struct that implements subcommand interface defined in cli.go.

The new struct can make use of baseCryptFlags, which represents shared command-line flags for encryption/decryption across all gfc crypto algorithms.

cli.go

It defines a subcommand interface, which all subcommands must implement. It is built around package github.com/alexflint/go-arg, where struct Gfc (defined in cli.go) has other subcommands as fields. gfc.Run is used to handle the program flow.

Gfc.Run

Regardless of the subcommands, gfc starts by validating that all parameters it received are both valid and usable (if it's a file, then gfc must be able to open it on a filesystem, etc).

After that, it reads bytes from infile to memory using readInput. Then, it calls preProcess, which transforms the input based on flags provided by the user. An example of pre-processing is compressing the input bytes when encrypting, or decoding the base64-encoded input when decrypting.

If pre-processing went well, the function moves on to call crypt, which handles cryptography in gfc. The input is encrypted/decrypted based on the command-line flags. This cryptography output is then post-processed by postProcess, which again, transform the bytes according to user CLI flags.

The crypto output maybe encoded to hex or base64 (encryption with encoding), or decompressed into plaintext if it was compressed during encryption (decrypting the pre-compressed ciphertext).

How data flows from the input state to the output state can is shown here

alt text

Documentation

Index

Constants

View Source
const (
	ErrMissingSubcommand cliError = iota
	ErrInvalidModeAES
	ErrFileIsDir
	ErrBadInfileIsText
	ErrBadOutfileDir
	ErrOutfileDirNotWritable
	ErrOutfileNotWritable
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Gfc

type Gfc struct {
	CommandAES      *cmdAES      `arg:"subcommand:aes" help:"Use gfc-aes for AES encryption: see 'gfc aes --help'"`
	CommandRSA      *cmdRSA      `arg:"subcommand:rsa" help:"Use gfc-rsa for RSA encryption: see 'gfc rsa --help'"`
	CommandChaCha20 *cmdChaCha20 `arg:"subcommand:cc20" help:"Use gfc-cc20 for ChaCha20/XChaCha20-Poly1305 encryption: see 'gfc cc20 --help'"`
}

Gfc represent the actual top-level gfc command.

func (*Gfc) Run

func (g *Gfc) Run() error

Run is the application code for gfc.

func (Gfc) Version

func (g Gfc) Version() string

Jump to

Keyboard shortcuts

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