示例#1
0
// Given an io.Reader, create a Sources iterator. Note that the Sources
// file is not OpenPGP signed, so one will need to verify the integrety
// of this file from the InRelease file before trusting any output.
func LoadSources(in io.Reader) (*Sources, error) {
	decoder, err := control.NewDecoder(in, nil)
	if err != nil {
		return nil, err
	}
	return &Sources{decoder: decoder}, nil
}
示例#2
0
func (c *FlagsConfig) Parse(readerIn io.Reader) error {
	reader := stripper.NewCommentStripper(readerIn)

	decoder, err := control.NewDecoder(bufio.NewReader(reader), nil)
	if err != nil {
		return err
	}

	for {
		entry := FlagsConfigEntry{}

		err := decoder.Decode(&entry)
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}

		if len(entry.Commands) == 0 {
			entry.Commands = []string{""}
		}

		for _, command := range entry.Commands {
			targetEntry := (*c)[command]
			targetEntry.Apply(entry)
			(*c)[command] = targetEntry
		}
	}

	return nil
}
示例#3
0
// Given an InRelease io.Reader, and the OpenPGP keyring
// to validate against, return the parsed InRelease file.
func LoadInRelease(in io.Reader, keyring *openpgp.EntityList) (*Release, error) {
	ret := Release{}
	decoder, err := control.NewDecoder(in, keyring)
	if err != nil {
		return nil, err
	}
	return &ret, decoder.Decode(&ret)
}
示例#4
0
func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
	reader := stripper.NewCommentStripper(readerIn)

	realDecoder, err := control.NewDecoder(bufio.NewReader(reader), nil)
	if err != nil {
		return nil, err
	}
	decoder := decoderWrapper{realDecoder}

	manifest := Manifest2822{
		Global: DefaultManifestEntry.Clone(),
	}

	if err := decoder.Decode(&manifest.Global); err != nil {
		return nil, err
	}
	if len(manifest.Global.Maintainers) < 1 {
		return nil, fmt.Errorf("missing Maintainers")
	}
	if invalidMaintainers := manifest.Global.InvalidMaintainers(); len(invalidMaintainers) > 0 {
		return nil, fmt.Errorf("invalid Maintainers: %q (expected format %q)", strings.Join(invalidMaintainers, ", "), MaintainersFormat)
	}
	if len(manifest.Global.Tags) > 0 {
		return nil, fmt.Errorf("global Tags not permitted")
	}

	for {
		entry := manifest.Global.Clone()

		err := decoder.Decode(&entry)
		if err == io.EOF {
			break
		}
		if err != nil {
			return nil, err
		}

		if len(entry.Tags) < 1 {
			return nil, fmt.Errorf("missing Tags")
		}
		if entry.GitRepo == "" || entry.GitFetch == "" || entry.GitCommit == "" {
			return nil, fmt.Errorf("Tags %q missing one of GitRepo, GitFetch, or GitCommit", entry.TagsString())
		}
		if !GitFetchRegex.MatchString(entry.GitFetch) {
			return nil, fmt.Errorf(`Tags %q has invalid GitFetch (must be "refs/heads/..." or "refs/tags/..."): %q`, entry.TagsString(), entry.GitFetch)
		}
		if !GitCommitRegex.MatchString(entry.GitCommit) {
			return nil, fmt.Errorf(`Tags %q has invalid GitCommit (must be a commit, not a tag or ref): %q`, entry.TagsString(), entry.GitCommit)
		}

		err = manifest.AddEntry(entry)
		if err != nil {
			return nil, err
		}
	}

	return &manifest, nil
}