Documentation ¶
Index ¶
- Variables
- func Base64(filename string) (b []byte, err error)
- func CopyFile(src, dst string) (int64, error)
- func DownloadFromWebStore(extensionID string, filename string) error
- func ID(filename string) (id string, err error)
- func LoadPrivateKey(filename string) (*rsa.PrivateKey, error)
- func NewPrivateKey() (*rsa.PrivateKey, error)
- func Pack(src string, dst string, pk *rsa.PrivateKey) (err error)
- func SavePrivateKey(filename string, key *rsa.PrivateKey) error
- func SetWebStoreURL(u string)
- func Unpack(filename string) error
- func UnpackTo(filename string, dirname string) error
- func Unzip(r io.ReaderAt, size int64, unpacked string) error
- func UnzipTo(basepath string, filename string) error
- func Zip(dst io.Writer, dirname string) error
- func ZipTo(filename string, dirname string) error
- type Extension
- func (e Extension) Base64() ([]byte, error)
- func (e Extension) ID() (string, error)
- func (e Extension) IsCRX3() bool
- func (e Extension) IsDir() bool
- func (e Extension) IsEmpty() bool
- func (e Extension) IsZip() bool
- func (e Extension) Pack(pk *rsa.PrivateKey) error
- func (e Extension) PackTo(dst string, pk *rsa.PrivateKey) error
- func (e Extension) String() string
- func (e Extension) Unpack() error
- func (e Extension) Unzip() error
- func (e Extension) Zip() error
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownFileExtension = errors.New("crx3: unknown file extension") ErrUnsupportedFileFormat = errors.New("crx3: unsupported file format") ErrExtensionNotSpecified = errors.New("crx3: extension id not specified") ErrPathNotFound = errors.New("crx3: filepath not found") ErrPrivateKeyNotFound = errors.New("crx3: private key not found") )
Functions ¶
func Base64 ¶
Base64 encodes an extension file to a base64 string. It returns a bytes and an error encountered while encodes, if any.
func CopyFile ¶
CopyFile copies the contents of the source file 'src' to the destination file 'dst'. It returns the number of bytes copied and any encountered error. If the source file does not exist, is not a regular file, or other errors occur during the copy, it returns an error with a descriptive message.
func DownloadFromWebStore ¶
DownloadFromWebStore downloads a Chrome extension from the web store. ExtensionID can be an identifier or an url.
func ID ¶
ID returns the extension ID extracted from a CRX (Chrome Extension) file specified by 'filename'. It checks if the file is in the CRX format, reads its header and signed data, and then converts the CRX ID into a string representation
func LoadPrivateKey ¶
func LoadPrivateKey(filename string) (*rsa.PrivateKey, error)
LoadPrivateKey loads the RSA private key from the specified 'filename' into memory. It returns the loaded private key or an error if the key cannot be loaded.
func NewPrivateKey ¶
func NewPrivateKey() (*rsa.PrivateKey, error)
NewPrivateKey returns a new RSA private key with a bit size of 2048.
func Pack ¶
func Pack(src string, dst string, pk *rsa.PrivateKey) (err error)
Pack packs a zip file or unzipped directory into a crx extension. It takes the source 'src' (zip file or directory), target 'dst' CRX file path, and a private key 'pk' (optional). If 'pk' is nil, it generates a new private key. It creates a CRX extension from the source and writes it to the destination.
func SavePrivateKey ¶
func SavePrivateKey(filename string, key *rsa.PrivateKey) error
SavePrivateKey saves the provided 'key' private key to the specified 'filename'. If 'key' is nil, it generates a new private key and saves it to the file.
func SetWebStoreURL ¶
func SetWebStoreURL(u string)
SetWebStoreURL sets the web store url to download extensions.
func Unpack ¶
Unpack unpacks a CRX (Chrome Extension) file specified by 'filename' to its original contents. It checks if the file is in the CRX format, reads its header and signed data, and then extracts and decompresses the original contents. The unpacked contents are placed in a directory with the same name as the original file (without the '.crx' extension).
func UnpackTo ¶
UnpackTo unpacks a CRX (Chrome Extension) file specified by 'filename' to the directory 'dirname'. If 'dirname' does not exist, it creates the directory before unpacking.
func Unzip ¶
Unzip extracts all files and directories from the provided ZIP archive. It takes an io.ReaderAt 'r', the size 'size' of the ZIP archive, and the target directory 'unpacked' for extraction. It iterates through the archive, creating directories and writing files as necessary.
func UnzipTo ¶
UnzipTo extracts the contents of a ZIP archive specified by 'filename' to the 'basepath' directory. It opens the ZIP file, creates the necessary directory structure, and extracts all files.
Types ¶
type Extension ¶
type Extension string
Extension represents an extension for google chrome.
func (Extension) Pack ¶
func (e Extension) Pack(pk *rsa.PrivateKey) error
Pack packs zip file or an unpacked directory into a CRX3 file.
func (Extension) PackTo ¶
func (e Extension) PackTo(dst string, pk *rsa.PrivateKey) error
PackTo packs zip file or an unpacked directory into a CRX3 file.