// ParseSHAFromURL downloads and reads a SHA checksum from an URL
15231
func ParseSHAFromURL(url string) (string, error) {
	r, err := http.Get(url)
	if err != nil {
		return "", errors.Wrap(err, "Error downloading checksum.")
	} else if r.StatusCode != http.StatusOK {
		return "", errors.Errorf("Error downloading checksum. Got HTTP Error: %s", r.Status)
	}

	defer r.Body.Close()
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return "", errors.Wrap(err, "Error reading checksum.")
	}

	return strings.Trim(string(body), "\n"), nil
}
11893
func ParseBlockCryptKeyServerHalf(s string) (BlockCryptKeyServerHalf, error) {
	buf, err := hex.DecodeString(s)
	if err != nil {
		return BlockCryptKeyServerHalf{}, errors.WithStack(err)
	}
	var serverHalf BlockCryptKeyServerHalf
	err = serverHalf.UnmarshalBinary(buf)
	if err != nil {
		return BlockCryptKeyServerHalf{}, err
	}
	return serverHalf, nil
}
593787
func checkURL(url string) error {
	resp, err := http.Get(url)
	glog.Infof("%s response: %v %+v", url, err, resp)
	if err != nil {
		return errors.Wrap(err, "checkURL")
	}
	if resp.StatusCode != http.StatusOK {
		return &util.RetriableError{
			Err: fmt.Errorf("unexpected response code: %d", resp.StatusCode),
		}
	}
	return nil
}
472263
func SimpleHashFromMap(m map[string][]byte) []byte {
	sm := newSimpleMap()
	for k, v := range m {
		sm.Set(k, v)
	}
	return sm.Hash()
}
1336263
func (i *Image) parseResponseFromURL(u string, result interface{}) error {
	resp, err := i.getResponseFromURL(u)
	if err != nil {
		return err
	}

	defer resp.Body.Close()

	dec := json.NewDecoder(resp.Body)
	if err := dec.Decode(&result); err != nil {
		return err
	}

	return nil
}
8101
func ParseURL(v string) (*StreamAddr, error) {
	u, err := url.Parse(v)
	if err != nil {
		return nil, errors.Annotate(err, "failed to parse URL").Err()
	}

	// Validate Scheme.
	if u.Scheme != logDogURLScheme {
		return nil, errors.Reason("URL scheme %q is not %s", u.Scheme, logDogURLScheme).Err()
	}
	addr := StreamAddr{
		Host: u.Host,
	}

	parts := strings.SplitN(u.Path, "/", 3)
	if len(parts) != 3 || len(parts[0]) != 0 {
		return nil, errors.Reason("URL path does not include both project and path components: %s", u.Path).Err()
	}

	addr.Project, addr.Path = ProjectName(parts[1]), StreamPath(parts[2])
	if err := addr.Project.Validate(); err != nil {
		return nil, errors.Annotate(err, "invalid project name: %q", addr.Project).Err()
	}

	if err := addr.Path.Validate(); err != nil {
		return nil, errors.Annotate(err, "invalid stream path: %q", addr.Path).Err()
	}

	return &addr, nil
}
119856
func decodeFirstHash(p *advRefsDecoder) decoderStateFn {
	// If the repository is empty, we receive a flush here (HTTP).
	if isFlush(p.line) {
		p.err = ErrEmptyAdvRefs
		return nil
	}

	if len(p.line) < hashSize {
		p.error("cannot read hash, pkt-line too short")
		return nil
	}

	if _, err := hex.Decode(p.hash[:], p.line[:hashSize]); err != nil {
		p.error("invalid hash text: %s", err)
		return nil
	}

	p.line = p.line[hashSize:]

	if p.hash.IsZero() {
		return decodeSkipNoRefs
	}

	return decodeFirstRef
}
423641
func ParseHeader(s string) http.Header {
	h := http.Header{}
	lines := strings.Split(s, "\n")
	rx := regexp.MustCompile(`^([^\s+]+):\s*(.*)$`)
	for _, line := range lines {
		m := rx.FindStringSubmatch(line)
		if len(m) == 3 {
			key := strings.TrimSpace(m[1])
			val := strings.TrimSpace(m[2])
			if len(key) > 0 {
				h.Add(key, val)
			}
		}
	}
	return h
}
1358938
func SpecFromURL(u *url.URL) (*Spec, error) {
	q := u.Query()
	sp := Spec{
		Context:   q.Get("context"),
		Namespace: q.Get("namespace"),
		Pod:       u.Hostname(),
		Container: q.Get("container"),
	}
	if sp.Context != "" && !validKubeIdentifier(sp.Context) {
		return nil, errors.Errorf("unsupported context name: %q", sp.Context)
	}
	if sp.Namespace != "" && !validKubeIdentifier(sp.Namespace) {
		return nil, errors.Errorf("unsupported namespace name: %q", sp.Namespace)
	}
	if sp.Pod == "" {
		return nil, errors.New("url lacks pod name")
	}
	if !validKubeIdentifier(sp.Pod) {
		return nil, errors.Errorf("unsupported pod name: %q", sp.Pod)
	}
	if sp.Container != "" && !validKubeIdentifier(sp.Container) {
		return nil, errors.Errorf("unsupported container name: %q", sp.Container)
	}
	return &sp, nil
}
389992
func LoadChecksumsFromReader(
	r io.Reader,
	weakHashSize int,
	strongHashSize int,
) ([]ChunkChecksum, error) {

	result := make([]ChunkChecksum, 0, 20)
	offset := uint(0)

	temp := ChunkChecksum{}

	for {
		weakBuffer := make([]byte, weakHashSize)
		n, err := io.ReadFull(r, weakBuffer)

		if n == weakHashSize {
			temp.ChunkOffset = offset
			temp.WeakChecksum = weakBuffer
		} else if n == 0 && err == io.EOF {
			break
		} else {
			return nil, ErrPartialChecksum
		}

		strongBuffer := make([]byte, strongHashSize)
		n, err = io.ReadFull(r, strongBuffer)

		if n == strongHashSize {
			temp.StrongChecksum = strongBuffer
			result = append(result, temp)

			if err == io.EOF {
				break
			}
		} else {
			return nil, ErrPartialChecksum
		}

		offset += 1
	}

	return result, nil
}
1251975
func (hs *httpSourceHandler) urlHash() (digest.Digest, error) {
	dt, err := json.Marshal(struct {
		Filename       string
		Perm, UID, GID int
	}{
		Filename: getFileName(hs.src.URL, hs.src.Filename, nil),
		Perm:     hs.src.Perm,
		UID:      hs.src.UID,
		GID:      hs.src.GID,
	})
	if err != nil {
		return "", err
	}
	return digest.FromBytes(dt), nil
}
783554
func (slc *HttpClient) CheckForHttpResponseErrorsSilently(data []byte) error {
	var decodedResponse map[string]interface{}
	parseErr := json.Unmarshal(data, &decodedResponse)
	if parseErr == nil {
		return slc.HasErrors(decodedResponse)
	}

	return nil
}
520081
func ascURLFromImgURL(u *url.URL) *url.URL {
	copy := *u
	copy.Path = ascPathFromImgPath(copy.Path)
	return &copy
}
216121
func parseMFAHeader(req *logical.Request) error {
	if req == nil {
		return fmt.Errorf("request is nil")
	}

	if req.Headers == nil {
		return nil
	}

	// Reset and initialize the credentials in the request
	req.MFACreds = make(map[string][]string)

	for _, mfaHeaderValue := range req.Headers[canonicalMFAHeaderName] {
		// Skip the header with no value in it
		if mfaHeaderValue == "" {
			continue
		}

		// Handle the case where only method name is mentioned and no value
		// is supplied
		if !strings.Contains(mfaHeaderValue, ":") {
			// Mark the presence of method name, but set an empty set to it
			// indicating that there were no values supplied for the method
			if req.MFACreds[mfaHeaderValue] == nil {
				req.MFACreds[mfaHeaderValue] = []string{}
			}
			continue
		}

		shardSplits := strings.SplitN(mfaHeaderValue, ":", 2)
		if shardSplits[0] == "" {
			return fmt.Errorf("invalid data in header %q; missing method name", MFAHeaderName)
		}

		if shardSplits[1] == "" {
			return fmt.Errorf("invalid data in header %q; missing method value", MFAHeaderName)
		}

		req.MFACreds[shardSplits[0]] = append(req.MFACreds[shardSplits[0]], shardSplits[1])
	}

	return nil
}
595404
func Checksum(path string) (checksum string, err error) {
	// Open executable
	var f *os.File
	if f, err = os.Open(path); err != nil {
		err = errors.Wrapf(err, "opening %s failed", path)
		return
	}
	defer f.Close()

	// Compute checksum
	var h = sha1.New()
	if _, err = io.Copy(h, f); err != nil {
		err = errors.Wrap(err, "copying file to hasher failed")
		return
	}
	checksum = base64.StdEncoding.EncodeToString(h.Sum(nil))
	return
}
533355
func ParseURL(us string) (*URL, error) {
	// if it's no URL build file URL and parse that
	nu, err := url.Parse(us)
	if err != nil {
		nu, err = url.Parse("gpgcli-gitcli-fs+file://" + us)
		if err != nil {
			return nil, err
		}
	}
	u := &URL{
		url: nu,
	}
	if err := u.parseScheme(); err != nil {
		return u, err
	}
	u.Path = nu.Path
	if nu.User != nil {
		u.Username = nu.User.Username()
		u.Password, _ = nu.User.Password()
	}
	if nu.Host == "~" {
		hd, err := homedir.Dir()
		if err != nil {
			return u, err
		}
		u.Path = filepath.Join(hd, u.Path)
		nu.Host = ""
	}
	u.Query = nu.Query()
	if nu.Host != "" {
		h, p, err := net.SplitHostPort(nu.Host)
		if err == nil {
			u.Host = h
			u.Port = p
		}
	} else if runtime.GOOS == "windows" {
		// only trim if this is a local path, e. g. file:///C:/Users/...
		// (specified in https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/)
		// In that case, u.Path will contain a leading slash.
		// (correctly, as per RFC 3986, see https://github.com/golang/go/issues/6027)
		u.Path = strings.TrimPrefix(u.Path, "/")
	}
	return u, nil
}
928381
func (c *AppPackageDeleteCall) Sha1Sum(sha1Sum string) *AppPackageDeleteCall {
	c.urlParams_.Set("sha1Sum", sha1Sum)
	return c
}