func (d *Deb) validate() error { _, err := d.f.Seek(0, 0) if err != nil { return &InvalidDeb{d, err} } rd := ar.NewReader(d.f) hdr, err := rd.Next() if err != nil { return &InvalidDeb{d, err} } hdr.Name = strings.Trim(hdr.Name, "/") if hdr.Name != "debian-binary" { err := fmt.Errorf("First file in .deb must be 'debian-binary', not '%s'", hdr.Name) return &InvalidDeb{d, err} } buf := make([]byte, 10) n, err := rd.Read(buf) if err != nil { return &InvalidDeb{d, err} } version := strings.TrimSpace(string(buf[:n])) if version != "2.0" { err := fmt.Errorf("Only v2.0 .deb files supported, not v%s", version) return &InvalidDeb{d, err} } _, err = d.f.Seek(0, 0) if err != nil { return &InvalidDeb{d, err} } return nil }
func (d *Deb) hashSections() (string, error) { h1 := sha1.New() h5 := md5.New() w := io.MultiWriter(h1, h5) _, err := d.f.Seek(0, 0) if err != nil { return "", &InvalidDeb{d, err} } s := "" rd := ar.NewReader(d.f) for { h1.Reset() h5.Reset() hdr, err := rd.Next() if err == io.EOF { return s, nil } else if err != nil { return "", &InvalidDeb{d, err} } _, err = io.Copy(w, rd) if err != nil { return "", &InvalidDeb{d, err} } h1x := hex.EncodeToString(h1.Sum(nil)) h5x := hex.EncodeToString(h5.Sum(nil)) s += fmt.Sprintf("\t%s %s %d %s\n", h5x, h1x, hdr.Size, hdr.Name) } }
func (d *Deb) findSection(name string) (io.Reader, error) { _, err := d.f.Seek(0, 0) if err != nil { return nil, &InvalidDeb{d, err} } rd := ar.NewReader(d.f) section := "" for section != name { hdr, err := rd.Next() if err == io.EOF { return nil, &NotFound{d, name} } else if err != nil { return nil, &InvalidDeb{d, err} } section = strings.Trim(hdr.Name, "/") } return rd, nil }