Documentation
¶
Overview ¶
Package ephcli provides progress bar functionality for file operations.
Index ¶
- Constants
- Variables
- func CheckExpiration(token string) (bool, error)
- func DecryptAES(key []byte, ciphertext []byte) ([]byte, error)
- func EncryptAES(key []byte, plaintext []byte) ([]byte, error)
- func EncryptAESKey(publicKeyPem, aesKey string) (string, error)
- func GenAESKey32bits() ([]byte, error)
- func LoadRSAPublicKey(pemString string) (*rsa.PublicKey, error)
- func Print(fl *dto.FileList) error
- func PrintCSV(fl *dto.FileList) error
- func PrintJSON(fl *dto.FileList) error
- func PrintYAML(fl *dto.FileList) error
- func Whoami(token string) (string, time.Time, error)
- type Box
- type ClientEphemeralfiles
- func (c *ClientEphemeralfiles) CloseProgressBar()
- func (c *ClientEphemeralfiles) CreateNewDownloadTransaction(fileID string) (string, string, error)
- func (c *ClientEphemeralfiles) DisableProgressBar()
- func (c *ClientEphemeralfiles) Download(uuidFile string, outputfile string) error
- func (c *ClientEphemeralfiles) DownloadE2E(fileID string) error
- func (c *ClientEphemeralfiles) DownloadEndpoint(uuidFile string) string
- func (c *ClientEphemeralfiles) DownloadPartE2E(outputFilePath string, transactionID string, aesKey []byte, part int) (int, error)
- func (c *ClientEphemeralfiles) DownloadPartE2EEndpoint(transactionID string, part int) string
- func (c *ClientEphemeralfiles) Fetch() (dto.FileList, error)
- func (c *ClientEphemeralfiles) FilesEndpoint() string
- func (c *ClientEphemeralfiles) GetBoxInfos() (*Box, error)
- func (c *ClientEphemeralfiles) GetFileInformationEndpoint(fileID string) string
- func (c *ClientEphemeralfiles) GetNewDownloadTransactionEndpoint(fileID string) string
- func (c *ClientEphemeralfiles) GetPublicKey() (string, string, string, error)
- func (c *ClientEphemeralfiles) GetPublicKeyEndpoint() string
- func (c *ClientEphemeralfiles) InitProgressBar(msg string, totalSize int64)
- func (c *ClientEphemeralfiles) Remove(uuidFileToRemove string) error
- func (c *ClientEphemeralfiles) SendAESKeyEndpoint(fileID string) string
- func (c *ClientEphemeralfiles) SendAESKeyToEndpoint(endpoint, encryptedAESKey string) error
- func (c *ClientEphemeralfiles) SetDebug()
- func (c *ClientEphemeralfiles) SetEndpoint(endpoint string)
- func (c *ClientEphemeralfiles) SetHTTPClient(client *http.Client)
- func (c *ClientEphemeralfiles) SetLogger(logger *slog.Logger)
- func (c *ClientEphemeralfiles) UpdateAESKeyForDownloadTransactionEndpoint(transactionID string) string
- func (c *ClientEphemeralfiles) Upload(fileToUpload string) error
- func (c *ClientEphemeralfiles) UploadE2E(fileToUpload string) error
- func (c *ClientEphemeralfiles) UploadE2EEndpoint(transactionID string) string
- func (c *ClientEphemeralfiles) UploadEndpoint() string
- func (c *ClientEphemeralfiles) UploadFileInChunks(aeskey []byte, filePath, targetURL string) error
- type E2EKeyBundle
Constants ¶
const ( // PEMLineLength is the standard length for PEM-encoded lines. PEMLineLength = 64 // AESKeySize32 is the size of AES-256 key in bytes. AESKeySize32 = 32 )
const DefaultAPIRequestTimeout = 5 * time.Second
DefaultAPIRequestTimeout is the default timeout for API requests.
const (
// DefaultBarWidth is the default width for progress bars.
DefaultBarWidth = 50
)
const (
// FilePermission is the permission for downloaded files.
FilePermission = 0600
)
Variables ¶
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.
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 )
var ( // ErrFileNotFound is returned when a requested file cannot be found. ErrFileNotFound = errors.New("file not found") )
Functions ¶
func CheckExpiration ¶
CheckExpiration checks if a JWT token has expired.
func DecryptAES ¶ added in v0.2.0
DecryptAES decrypts ciphertext using AES decryption with the provided key.
func EncryptAES ¶ added in v0.2.0
EncryptAES encrypts plaintext using AES encryption with the provided key.
func EncryptAESKey ¶ added in v0.2.0
EncryptAESKey encrypts an AES key using RSA public key encryption.
func GenAESKey32bits ¶ added in v0.2.0
GenAESKey32bits generates a 32 bits AES key.
func LoadRSAPublicKey ¶ added in v0.2.0
LoadRSAPublicKey loads an RSA public key from a PEM-encoded string.
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 (*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
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.