pkgformat

module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0

README

pkgformat

CI Go Reference

A pure-Go library for Linux package formats. It builds, reads, verifies and signs packages; reads and writes repository indexes; and fetches from repositories, with dependency resolution. It calls none of the native packaging tools.

Install

go get github.com/M0Rf30/pkgformat

Requires Go 1.27 or later.

Formats

Format Package Packages Repository index Repository client
RPM (format 4 and 6) rpm write, read, verify, sign; installed database (rpm/rpmdb): read repodata: write, read, sign, modules rpm/dnf
Debian deb write, read, verify, sign; installed database (deb.StatusDB): read Packages, Release, InRelease, by-hash, Contents, Translations, Packages.diff: write, read, sign, verify deb/apt
Debian sources deb/source .dsc, .changes, .buildinfo: write, read, sign, verify; source packages 1.0, 3.0 (quilt), 3.0 (native): unpack, build (3.0) Sources: write, read
Alpine apk write, read, verify, sign (RSA SHA-1 and SHA-256); installed database (apk.InstalledDB): read APKINDEX: write, read, sign, verify apk.Client
Alpine v3 (ADB) apk/adb write (apk mkpkg compatible), read, verify, sign (RSA, ECDSA), extract; apk.ParsePackage reads v3 too; verified against apk-tools 3.0.9 APKINDEX.adb: write (apk mkndx compatible), read, sign, verify
Arch Linux pacman write, read, sign; installed database (pacman.LocalDB): read sync database: write, read pacman.Client

Each format has its own README with its supported features, examples and security notes for untrusted input.

Shared packages

Package Purpose
gpg OpenPGP signing (cleartext, detached armored, detached binary) and verification against a keyring
httpclient HTTP client with capped bodies and one retry policy and classifier (transport errors, 408/429/5xx)
download Resumable downloads (Range + If-Range) with length and checksum checks, atomic rename and bounded concurrency
safepath Containment checks for untrusted archive entry names and symlink targets
xzlimit xz decoding that rejects oversized dictionaries before allocating them

All packages take their settings through options structs. They keep no package-level state, and they log only through an optional *slog.Logger.

Commands

Command Purpose
cmd/tar2rpm Turn a tar archive into an rpm package
cmd/rpmsample Write a sample rpm package, to test other rpm tools

Security

Every parser is written for untrusted input. Sizes and counts are bounded, and errors are typed. Archive extraction stays inside its target directory. Every parser has fuzz targets, and CI runs all of them.

License

Apache License 2.0, see LICENSE.

Directories

Path Synopsis
apk
Package apk builds, reads, verifies and signs Alpine Linux packages (.apk, the v2 format of apk-tools) and repository indexes, and fetches them from repositories.
Package apk builds, reads, verifies and signs Alpine Linux packages (.apk, the v2 format of apk-tools) and repository indexes, and fetches them from repositories.
adb
Package adb reads, verifies and writes APKv3 files: the packages and the repository indexes of apk-tools 3.
Package adb reads, verifies and writes APKv3 files: the packages and the repository indexes of apk-tools 3.
cmd
rpmsample command
rpmsample creates an rpm file with some known files, which can be used to test the output of pack against other rpm implementations.
rpmsample creates an rpm file with some known files, which can be used to test the output of pack against other rpm implementations.
tar2rpm command
deb
Package deb reads, writes and indexes Debian binary packages and the metadata of apt repositories.
Package deb reads, writes and indexes Debian binary packages and the metadata of apt repositories.
apt
Package apt is a client for Debian apt repositories that needs no apt installation: it refreshes package indexes, reads them, resolves dependencies and downloads packages with their integrity enforced.
Package apt is a client for Debian apt repositories that needs no apt installation: it refreshes package indexes, reads them, resolves dependencies and downloads packages with their integrity enforced.
source
Package source reads, verifies, unpacks, builds and indexes Debian source packages.
Package source reads, verifies, unpacks, builds and indexes Debian source packages.
Package download fetches files over HTTP with resume, retry, integrity checks and bounded concurrency, on the shared httpclient transport.
Package download fetches files over HTTP with resume, retry, integrity checks and bounded concurrency, on the shared httpclient transport.
Package gpg signs and verifies with OpenPGP.
Package gpg signs and verifies with OpenPGP.
Package httpclient fetches small and large HTTP resources for repository clients: every body is size-capped, transient failures are retried with jittered exponential backoff, and files are written atomically.
Package httpclient fetches small and large HTTP resources for repository clients: every body is size-capped, transient failures are retried with jittered exponential backoff, and files are written atomically.
internal
apkver
Package apkver is the Alpine version and dependency syntax, shared by the v2 and v3 package formats: it tells valid versions from invalid ones, orders them as apk does and splits dependency specifications.
Package apkver is the Alpine version and dependency syntax, shared by the v2 and v3 package formats: it tells valid versions from invalid ones, orders them as apk does and splits dependency specifications.
limitio
Package limitio bounds how much of a reader is consumed.
Package limitio bounds how much of a reader is consumed.
modzipcheck command
Command modzipcheck builds the module zip of the committed tree, as the Go module proxy would for a tag, and fails when any file breaks the module zip rules.
Command modzipcheck builds the module zip of the committed tree, as the Go module proxy would for a tag, and fails when any file breaks the module zip rules.
pathseg
Package pathseg is the one definition of a plain path segment, shared by every place that turns client-supplied names into repository paths, coordinates, file names or remote URLs.
Package pathseg is the one definition of a plain path segment, shared by every place that turns client-supplied names into repository paths, coordinates, file names or remote URLs.
Package pacman builds, reads and indexes Arch Linux packages and repositories in pure Go, without makepkg, pacman or repo-add.
Package pacman builds, reads and indexes Arch Linux packages and repositories in pure Go, without makepkg, pacman or repo-add.
rpm
Package rpm reads, verifies and signs RPM packages.
Package rpm reads, verifies and signs RPM packages.
cpio
Package cpio reads, writes and extracts the cpio archives that make up the payload of rpm packages: the "newc" format of format 4 packages and the stripped variant of format 6 packages, which holds only the index of each file in the header.
Package cpio reads, writes and extracts the cpio archives that make up the payload of rpm packages: the "newc" format of format 4 packages and the stripped variant of format 6 packages, which holds only the index of each file in the header.
dnf
Package dnf is a client for dnf/yum repositories: it reads .repo files, refreshes repository metadata into a cache, indexes it, resolves package dependencies and downloads verified packages.
Package dnf is a client for dnf/yum repositories: it reads .repo files, refreshes repository metadata into a cache, indexes it, resolves package dependencies and downloads verified packages.
internal/header
Package header encodes RPM headers: the signature header and the main header of a package share one binary layout, which is written here for both the package writer and the signature rewriting of the reader.
Package header encodes RPM headers: the signature header and the main header of a package share one binary layout, which is written here for both the package writer and the signature rewriting of the reader.
pack
Package pack writes rpm packages.
Package pack writes rpm packages.
repodata
Package repodata writes and reads the metadata of an RPM repository: the repomd.xml index and the primary.xml, filelists.xml, other.xml, comps.xml and modules.yaml documents that dnf and yum fetch.
Package repodata writes and reads the metadata of an RPM repository: the repomd.xml index and the primary.xml, filelists.xml, other.xml, comps.xml and modules.yaml documents that dnf and yum fetch.
richdep
Package richdep parses and evaluates the rich (boolean) dependencies of RPM: "(foo and bar)", "(foo if bar)", "(foo unless bar else baz)", "((a or b) with c)" and the like, as rpm 4.12 and later read them.
Package richdep parses and evaluates the rich (boolean) dependencies of RPM: "(foo and bar)", "(foo if bar)", "(foo unless bar else baz)", "((a or b) with c)" and the like, as rpm 4.12 and later read them.
rpmdb
Package rpmdb reads the database in which rpm records the packages installed on a host: SQLite (rpm 4.16 and later on Fedora, RHEL 9, Rocky 9, AlmaLinux 9, ...), the BerkeleyDB hash database of rpm 4.15 and earlier (RHEL 8 and its rebuilds, CentOS 7), and the "ndb" database of openSUSE and SUSE Linux Enterprise.
Package rpmdb reads the database in which rpm records the packages installed on a host: SQLite (rpm 4.16 and later on Fedora, RHEL 9, Rocky 9, AlmaLinux 9, ...), the BerkeleyDB hash database of rpm 4.15 and earlier (RHEL 8 and its rebuilds, CentOS 7), and the "ndb" database of openSUSE and SUSE Linux Enterprise.
tag
Package tag holds the numeric constants of the RPM header format: the types of header entries, the tag numbers of the general header and of the signature header (mirroring rpmtag.h of rpm), the bitmasks found in some of the tags, and the OpenPGP hash algorithm identifiers used by signatures.
Package tag holds the numeric constants of the RPM header format: the types of header entries, the tag numbers of the general header and of the signature header (mirroring rpmtag.h of rpm), the bitmasks found in some of the tags, and the OpenPGP hash algorithm identifiers used by signatures.
Package safepath holds the path-containment checks an archive or package extractor needs: it defends against zip-slip path traversal and symlink-escape attacks (deb data.tar, RPM CPIO payloads, APK tarballs, container rootfs layers, source archives).
Package safepath holds the path-containment checks an archive or package extractor needs: it defends against zip-slip path traversal and symlink-escape attacks (deb data.tar, RPM CPIO payloads, APK tarballs, container rootfs layers, source archives).
Package xzlimit guards the xz decoder against streams that declare an oversized dictionary: the decoder allocates whatever the header asks for, up to 4 GiB, before reading any data.
Package xzlimit guards the xz decoder against streams that declare an oversized dictionary: the decoder allocates whatever the header asks for, up to 4 GiB, before reading any data.

Jump to

Keyboard shortcuts

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