Skip to content

Commit

Permalink
feat: add package digest (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen authored May 17, 2023
1 parent 7fdfe59 commit b97c85e
Show file tree
Hide file tree
Showing 4 changed files with 2,963 additions and 3,232 deletions.
6 changes: 6 additions & 0 deletions pkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpmdb
import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"path/filepath"
"strings"
Expand All @@ -24,6 +25,7 @@ type PackageInfo struct {
Modularitylabel string
Summary string
PGP string
SigMD5 string
DigestAlgorithm DigestAlgorithm
InstallTime int
BaseNames []string
Expand Down Expand Up @@ -230,6 +232,10 @@ func getNEVRA(indexEntries []indexEntry) (*PackageInfo, error) {
return nil, xerrors.Errorf("failed to parse installtime: %w", err)
}
pkgInfo.InstallTime = installTime
case RPMTAG_SIGMD5:
// It is just string that we need to encode to hex
digest := bytes.TrimRight(ie.Data, "\x00")
pkgInfo.SigMD5 = hex.EncodeToString(digest)
case RPMTAG_PGP:
type pgpSig struct {
_ [3]byte
Expand Down
4 changes: 4 additions & 0 deletions pkg/rpmdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func TestRpmDB_Package(t *testing.T) {
License: "PSF - see LICENSE",
Vendor: "CentOS",
Summary: "An interpreted, interactive, object-oriented programming language.",
SigMD5: "ebfb56be33b146ef39180a090e581258",
PGP: "",
InstallTime: 1459411575,
Provides: []string{
Expand Down Expand Up @@ -188,6 +189,7 @@ func TestRpmDB_Package(t *testing.T) {
License: "LGPLv2+ and LGPLv2+ with exceptions and GPLv2+",
Vendor: "CentOS",
Summary: "The GNU libc libraries",
SigMD5: "89e843d7979a50a26e2ea1924ef3e213",
DigestAlgorithm: PGPHASHALGO_SHA256,
PGP: "RSA/SHA1, Wed Jun 20 11:36:27 2018, Key ID 0946fca2c105b9de",
InstallTime: 1538857091,
Expand Down Expand Up @@ -589,6 +591,7 @@ func TestRpmDB_Package(t *testing.T) {
Vendor: "CentOS",
Modularitylabel: "nodejs:10:8020020200707141642:6a468ee4",
Summary: "JavaScript runtime",
SigMD5: "bac7919c2369f944f9da510bbd01370b",
PGP: "RSA/SHA256, Tue Jul 7 16:08:24 2020, Key ID 05b555b38483c65d",
DigestAlgorithm: PGPHASHALGO_SHA256,
InstallTime: 1606911097,
Expand Down Expand Up @@ -684,6 +687,7 @@ func TestRpmDB_Package(t *testing.T) {
License: "MIT",
Vendor: "Microsoft Corporation",
Summary: "An URL retrieval utility and library",
SigMD5: "b5f5369ae91df3672fa3338669ec5ca2",
DigestAlgorithm: PGPHASHALGO_SHA256,
PGP: "RSA/SHA256, Thu Jan 27 09:02:11 2022, Key ID 0cd9fed33135ce90",
InstallTime: 1643279454,
Expand Down
Loading

0 comments on commit b97c85e

Please sign in to comment.