Browse Source

Handle checksums correctly

v0
maze 3 years ago
parent
commit
025661f07a
3 changed files with 82 additions and 25 deletions
  1. +14
    -3
      package.go
  2. +6
    -5
      packagebuild.go
  3. +62
    -17
      packagebuild_test.go

+ 14
- 3
package.go View File

@@ -322,9 +322,20 @@ func setPackageValue(o interface{}, v reflect.Value, value, encoding string) (er
v.SetBytes(b)
}
case [][]byte:
switch encoding {
case "":
v.Set(reflect.Append(v, reflect.ValueOf([]byte(value))))
for _, part := range strings.Fields(value) {
if part == "SKIP" && (encoding == "skip" || strings.HasSuffix(encoding, ",skip")) {
continue
}
switch strings.SplitN(encoding, ",", 2)[0] {
case "":
v.Set(reflect.Append(v, reflect.ValueOf([]byte(part))))
case "hex":
var b []byte
if b, err = hex.DecodeString(part); err != nil {
return fmt.Errorf("archlinux: invalid hex encoded value %q: %v", value, err)
}
v.Set(reflect.Append(v, reflect.ValueOf(b)))
}
}
case time.Time:
var i int64


+ 6
- 5
packagebuild.go View File

@@ -22,11 +22,12 @@ type PackageBuild struct {
// SourceArch are arch specific sources
SourceArch map[string][]string

MD5Sums [][]byte
SHA1Sums [][]byte
SHA256Sums [][]byte
SHA384Sums [][]byte
SHA512Sums [][]byte
// MD5Sums are the checksums of the sources
MD5Sums [][]byte `srcinfo:"md5sums,hex,skip"`
SHA1Sums [][]byte `srcinfo:"sha1sums,hex,skip"`
SHA256Sums [][]byte `srcinfo:"sha256sums,hex,skip"`
SHA384Sums [][]byte `srcinfo:"sha384sums,hex,skip"`
SHA512Sums [][]byte `srcinfo:"sha512sums,hex,skip"`
}

// ReadPackageBuild reads a PKGBUILD file


+ 62
- 17
packagebuild_test.go View File

@@ -2,33 +2,78 @@ package archlinux

import (
"bytes"
"encoding/hex"
"testing"
)

func TestReadSrcInfo(t *testing.T) {
build, err := ReadSrcInfo(bytes.NewBufferString(testReadSrcInfo))
if err != nil {
t.Fatal(err)
}
t.Run(build.String(), func(t *testing.T) {
if l := len(build.Packages); l != 2 {
t.Fatalf(`expected 2 packages, got %d`, l)
for _, test := range []struct {
SrcInfo string
Packages int
MD5Sums int
SHA256Sums int
Depends int
}{
{testReadSrcInfoPwnypack, 1, 0, 1, 0},
{testReadSrcInfoPythonPyJnius, 2, 1, 0, 2},
} {
build, err := ReadSrcInfo(bytes.NewBufferString(test.SrcInfo))
if err != nil {
t.Fatal(err)
}
t.Run("packages", func(t *testing.T) {
for name, pkg := range build.Packages {
t.Run(name, func(t *testing.T) {
t.Log(pkg)
if l := len(pkg.Depends); l != 2 {
t.Fatalf(`expected 2 dependencies, got %d`, l)
}
})
t.Run(build.String(), func(t *testing.T) {
if l := len(build.Packages); l != test.Packages {
t.Fatalf(`expected %d packages, got %d`, test.Packages, l)
}
if l := len(build.MD5Sums); l != test.MD5Sums {
t.Fatalf(`expected %d md5sums, got %d`, test.MD5Sums, l)
}
if l := len(build.SHA256Sums); l != test.SHA256Sums {
t.Fatalf(`expected %d sha256sums, got %d`, test.SHA256Sums, l)
}
if len(build.MD5Sums) > 0 {
t.Log("MD5", hex.EncodeToString(build.MD5Sums[0]))
}
if len(build.SHA256Sums) > 0 {
t.Log("SHA256", hex.EncodeToString(build.SHA256Sums[0]))
}
t.Run("packages", func(t *testing.T) {
for name, pkg := range build.Packages {
t.Run(name, func(t *testing.T) {
t.Log(pkg)
if l := len(pkg.Depends); l != test.Depends {
t.Fatalf(`expected %d dependencies, got %d`, test.Depends, l)
}
})
}
})
})
})
}
}

var (
testReadSrcInfo = `pkgbase = python-pyjnius
testReadSrcInfoPwnypack = `pkgbase = pwnypack
pkgdesc = Official Certified Edible Dinosaurs CTF toolkit
pkgver = 0.8.0
pkgrel = 1
url = https://github.com/edibledinos/pwnypack
arch = any
license = MIT
makedepends = python
depends = ipython
depends = nasm
depends = python
depends = python-capstone
depends = python-nose
depends = python-six
options = !emptydirs
source = https://pypi.python.org/packages/0e/e5/7ea712cc0a2b37a1efc1ae314ae1c39438a16a70ac43e36f3d190911ce94/pwnypack-0.8.0.tar.gz
sha256sums = 30d88155707a9b2a11aaf6bc8004dddc7c7545d8fa8f17b8d42de54e87a1b57d

pkgname = pwnypack

`
testReadSrcInfoPythonPyJnius = `pkgbase = python-pyjnius
pkgdesc = Python module to access Java class as Python class, using JNI.
pkgver = 1.1.1
pkgrel = 1


Loading…
Cancel
Save