ephcli

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package ephcli provides progress bar functionality for file operations.

Index

Constants

View Source
const (
	// PEMLineLength is the standard length for PEM-encoded lines.
	PEMLineLength = 64
	// AESKeySize32 is the size of AES-256 key in bytes.
	AESKeySize32 = 32
)
View Source
const DefaultAPIRequestTimeout = 5 * time.Second

DefaultAPIRequestTimeout is the default timeout for API requests.

View Source
const (
	// DefaultBarWidth is the default width for progress bars.
	DefaultBarWidth = 50
)
View Source
const (
	// FilePermission is the permission for downloaded files.
	FilePermission = 0600
)

Variables

View Source
var (
	// HTTP and API errors.
	ErrUnexpectedStatusCode = errors.New("unexpected status code")
	ErrSendingRequest       = errors.New("error sending request")
	ErrCreatingRequest      = errors.New("error creating request")
	ErrDecodingResponse     = errors.New("error decoding response")
	ErrReadingResponse      = errors.New("error reading response")

	// Encryption and security errors.
	ErrParsePEMBlock       = errors.New("failed to parse PEM block")
	ErrParsePublicKey      = errors.New("failed to parse public key")
	ErrNotRSAPublicKey     = errors.New("not an RSA public key")
	ErrEncryptionFailed    = errors.New("encryption failed")
	ErrCiphertextTooShort  = errors.New("ciphertext too short")
	ErrGeneratingAESKey    = errors.New("error generating AES key")
	ErrCreatingCipherBlock = errors.New("error creating new cipher block")
	ErrGeneratingRandomIV  = errors.New("error generating random IV")

	// File and I/O errors.
	ErrOpeningFile        = errors.New("error opening file")
	ErrGettingFileInfo    = errors.New("error getting file info")
	ErrReadingChunk       = errors.New("error reading chunk")
	ErrEncryptingChunk    = errors.New("error encrypting chunk")
	ErrCreatingFormFile   = errors.New("error creating form file")
	ErrWritingChunkToForm = errors.New("error writing chunk to form")
	ErrClosingWriter      = errors.New("error closing writer")
	ErrSeekingInFile      = errors.New("error seeking in file")
	ErrWritingChunkToFile = errors.New("error writing chunk to file")
	ErrDecryptingChunk    = errors.New("error decrypting chunk")

	// Payload and marshalling errors.
	ErrMarshallingPayload = errors.New("error marshalling payload")

	// GitHub release errors.
	ErrGettingLatestRelease = errors.New("error getting latest release")

	// Header and response errors.
	ErrDecodePEMBlock             = errors.New("failed to decode PEM block containing public key")
	ErrMissingHeaderFileID        = errors.New("missing X-File-Id header")
	ErrMissingHeaderPublicKey     = errors.New("missing X-File-Public-Key header")
	ErrMissingHeaderTransactionID = errors.New("missing X-Transaction-Id header")
	ErrMissingHeaderUploadID      = errors.New("missing X-Upload-Id header")
)

Error constants for the ephcli package.

View Source
var (
	// ErrInvalidToken is returned when a JWT token is invalid or malformed.
	ErrInvalidToken = errors.New("invalid token")
	// Now is a function that returns the current time, exposed for testing purposes.
	Now func() time.Time
)
View Source
var (
	// ErrFileNotFound is returned when a requested file cannot be found.
	ErrFileNotFound = errors.New("file not found")
)

Functions

func CheckExpiration

func CheckExpiration(token string) (bool, error)

CheckExpiration checks if a JWT token has expired.

func DecryptAES added in v0.2.0

func DecryptAES(key []byte, ciphertext []byte) ([]byte, error)

DecryptAES decrypts ciphertext using AES decryption with the provided key.

func EncryptAES added in v0.2.0

func EncryptAES(key []byte, plaintext []byte) ([]byte, error)

EncryptAES encrypts plaintext using AES encryption with the provided key.

func EncryptAESKey added in v0.2.0

func EncryptAESKey(publicKeyPem, aesKey string) (string, error)

EncryptAESKey encrypts an AES key using RSA public key encryption.

func GenAESKey32bits added in v0.2.0

func GenAESKey32bits() ([]byte, error)

GenAESKey32bits generates a 32 bits AES key.

func LoadRSAPublicKey added in v0.2.0

func LoadRSAPublicKey(pemString string) (*rsa.PublicKey, error)

LoadRSAPublicKey loads an RSA public key from a PEM-encoded string.

func Print added in v0.2.0

func Print(fl *dto.FileList) error

Print prints the list of files as a table.

func PrintCSV added in v0.2.0

func PrintCSV(fl *dto.FileList) error

PrintCSV prints the list of files as a CSV.

func PrintJSON added in v0.2.0

func PrintJSON(fl *dto.FileList) error

PrintJSON prints the list of files as JSON.

func PrintYAML added in v0.2.0

func PrintYAML(fl *dto.FileList) error

PrintYAML prints the list of files as YAML.

func Whoami

func Whoami(token string) (string, time.Time, error)

Whoami extracts user information from a JWT token, returning email and expiration time.

Types

type Box

type Box struct {
	CapacityMb  int64 `json:"capacity_mb"`
	UsedMb      int64 `json:"used_mb"`
	RemainingMb int64 `json:"remaining_mb"`
}

Box represents storage capacity and usage information for a user's box.

type ClientEphemeralfiles

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

ClientEphemeralfiles is the client to interact with the API.

func NewClient

func NewClient(token string) *ClientEphemeralfiles

NewClient creates a new client.

func (*ClientEphemeralfiles) CloseProgressBar added in v0.2.0

func (c *ClientEphemeralfiles) CloseProgressBar()

CloseProgressBar clears and closes the progress bar.

func (*ClientEphemeralfiles) CreateNewDownloadTransaction added in v0.2.0

func (c *ClientEphemeralfiles) CreateNewDownloadTransaction(
	fileID string,
) (string, string, error)

CreateNewDownloadTransaction creates a new E2E download transaction and returns the transaction ID and public key.

func (*ClientEphemeralfiles) DisableProgressBar

func (c *ClientEphemeralfiles) DisableProgressBar()

DisableProgressBar disables the progress bar for this client.

func (*ClientEphemeralfiles) Download

func (c *ClientEphemeralfiles) Download(uuidFile string, outputfile string) error

Download downloads a file from the server and saves it to the outputfile If the outputfile is empty, the file will be saved to the current directory with the same name as the file on the server (retrieving the name from the Content-Disposition header).

func (*ClientEphemeralfiles) DownloadE2E added in v0.2.0

func (c *ClientEphemeralfiles) DownloadE2E(fileID string) error

DownloadE2E downloads and decrypts a file using end-to-end encryption.

func (*ClientEphemeralfiles) DownloadEndpoint

func (c *ClientEphemeralfiles) DownloadEndpoint(uuidFile string) string

DownloadEndpoint returns the API endpoint URL for downloading a file by UUID.

func (*ClientEphemeralfiles) DownloadPartE2E added in v0.2.0

func (c *ClientEphemeralfiles) DownloadPartE2E(
	outputFilePath string, transactionID string, aesKey []byte, part int,
) (int, error)

DownloadPartE2E downloads and decrypts a specific part of an E2E encrypted file.

func (*ClientEphemeralfiles) DownloadPartE2EEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) DownloadPartE2EEndpoint(transactionID string, part int) string

DownloadPartE2EEndpoint returns the API endpoint URL for downloading a specific part of an E2E encrypted file.

func (*ClientEphemeralfiles) Fetch

func (c *ClientEphemeralfiles) Fetch() (dto.FileList, error)

Fetch retrieves the list of files from the server.

func (*ClientEphemeralfiles) FilesEndpoint

func (c *ClientEphemeralfiles) FilesEndpoint() string

FilesEndpoint returns the endpoint for the files.

func (*ClientEphemeralfiles) GetBoxInfos

func (c *ClientEphemeralfiles) GetBoxInfos() (*Box, error)

GetBoxInfos retrieves storage capacity and usage information for the current user's box.

func (*ClientEphemeralfiles) GetFileInformationEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) GetFileInformationEndpoint(fileID string) string

GetFileInformationEndpoint returns the API endpoint URL for retrieving file information.

func (*ClientEphemeralfiles) GetNewDownloadTransactionEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) GetNewDownloadTransactionEndpoint(fileID string) string

GetNewDownloadTransactionEndpoint returns the API endpoint URL for creating a new download transaction.

func (*ClientEphemeralfiles) GetPublicKey added in v0.2.0

func (c *ClientEphemeralfiles) GetPublicKey() (string, string, string, error)

GetPublicKey retrieves the server's public key and creates a new upload transaction.

func (*ClientEphemeralfiles) GetPublicKeyEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) GetPublicKeyEndpoint() string

GetPublicKeyEndpoint returns the API endpoint URL for retrieving the server's public key.

func (*ClientEphemeralfiles) InitProgressBar added in v0.2.0

func (c *ClientEphemeralfiles) InitProgressBar(msg string, totalSize int64)

InitProgressBar initializes a progress bar with the given message and total size.

func (*ClientEphemeralfiles) Remove

func (c *ClientEphemeralfiles) Remove(uuidFileToRemove string) error

Remove deletes a file from the ephemeralfiles service by its UUID.

func (*ClientEphemeralfiles) SendAESKeyEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) SendAESKeyEndpoint(fileID string) string

SendAESKeyEndpoint returns the API endpoint URL for sending an AES key for a file.

func (*ClientEphemeralfiles) SendAESKeyToEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) SendAESKeyToEndpoint(endpoint, encryptedAESKey string) error

SendAESKeyToEndpoint sends an encrypted AES key to the specified endpoint.

func (*ClientEphemeralfiles) SetDebug added in v0.2.0

func (c *ClientEphemeralfiles) SetDebug()

SetDebug sets the logger to debug Disable the progress bar.

func (*ClientEphemeralfiles) SetEndpoint

func (c *ClientEphemeralfiles) SetEndpoint(endpoint string)

SetEndpoint sets the API endpoint for this client.

func (*ClientEphemeralfiles) SetHTTPClient

func (c *ClientEphemeralfiles) SetHTTPClient(client *http.Client)

SetHTTPClient sets the HTTP client for this client.

func (*ClientEphemeralfiles) SetLogger added in v0.2.0

func (c *ClientEphemeralfiles) SetLogger(logger *slog.Logger)

SetLogger sets the logger.

func (*ClientEphemeralfiles) UpdateAESKeyForDownloadTransactionEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) UpdateAESKeyForDownloadTransactionEndpoint(transactionID string) string

UpdateAESKeyForDownloadTransactionEndpoint returns the API endpoint URL for updating the AES key in a download transaction.

func (*ClientEphemeralfiles) Upload

func (c *ClientEphemeralfiles) Upload(fileToUpload string) error

Upload uploads a file to the ephemeralfiles service.

func (*ClientEphemeralfiles) UploadE2E added in v0.2.0

func (c *ClientEphemeralfiles) UploadE2E(fileToUpload string) error

UploadE2E uploads a file using end-to-end encryption.

func (*ClientEphemeralfiles) UploadE2EEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) UploadE2EEndpoint(transactionID string) string

UploadE2EEndpoint returns the API endpoint URL for E2E encrypted file uploads.

func (*ClientEphemeralfiles) UploadEndpoint

func (c *ClientEphemeralfiles) UploadEndpoint() string

UploadEndpoint returns the API endpoint URL for file uploads.

func (*ClientEphemeralfiles) UploadFileInChunks added in v0.2.0

func (c *ClientEphemeralfiles) UploadFileInChunks(aeskey []byte, filePath, targetURL string) error

UploadFileInChunks uploads a file in encrypted chunks for E2E encryption.

type E2EKeyBundle added in v0.2.0

type E2EKeyBundle struct {
	AESKey          []byte
	HexString       string
	EncryptedAESKey string
}

E2EKeyBundle represents an AES key with its encrypted version.

func GenerateAndEncryptAESKey added in v0.2.0

func GenerateAndEncryptAESKey(publicKey string) (*E2EKeyBundle, error)

GenerateAndEncryptAESKey creates an AES key and encrypts it with the given public key.

Jump to

Keyboard shortcuts

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