// Fingerprint returns a 64-bit fingerprint of the given vector.
// The fingerprint f of a given 64-dimension vector v is defined as follows:
//   f[i] = 1 if v[i] >= 0
//   f[i] = 0 if v[i] < 0
961017
func Fingerprint(v Vector) uint64 {
	var f uint64
	for i := uint8(0); i < 64; i++ {
		if v[i] >= 0 {
			f |= (1 << i)
		}
	}
	return f
}
767937
func (ns *Namespace) Fingerprint(args ...interface{}) (resource.Resource, error) {
	if len(args) < 1 || len(args) > 2 {
		return nil, errors.New("must provide a Resource and (optional) crypto algo")
	}

	var algo string
	resIdx := 0

	if len(args) == 2 {
		resIdx = 1
		var err error
		algo, err = cast.ToStringE(args[0])
		if err != nil {
			return nil, err
		}
	}

	r, ok := args[resIdx].(resource.Resource)
	if !ok {
		return nil, fmt.Errorf("%T is not a Resource", args[resIdx])
	}

	return ns.integrityClient.Fingerprint(r, algo)
}
136501
func Fingerprint256(data []byte) string {
	d := sha256.New()
	_, _ = d.Write(data) // Never returns an error
	return base64.RawURLEncoding.EncodeToString(d.Sum(nil))
}
306000
func (e *GroupExpr) FingerPrint() string {
	if e.selfFingerprint == "" {
		e.selfFingerprint = fmt.Sprintf("%v", e.ExprNode.ID())
		for i := range e.Children {
			e.selfFingerprint += e.Children[i].FingerPrint()
		}
	}
	return e.selfFingerprint
}
195041
func ThumbprintSHA1(cert *x509.Certificate) string {
	sum := sha1.Sum(cert.Raw)
	hex := make([]string, len(sum))
	for i, b := range sum {
		hex[i] = fmt.Sprintf("%02X", b)
	}
	return strings.Join(hex, ":")
}
1307421
func (c *Client) updateNodeFromFingerprint(response *fingerprint.FingerprintResponse) *structs.Node {
	c.configLock.Lock()
	defer c.configLock.Unlock()

	nodeHasChanged := false

	for name, newVal := range response.Attributes {
		oldVal := c.config.Node.Attributes[name]
		if oldVal == newVal {
			continue
		}

		nodeHasChanged = true
		if newVal == "" {
			delete(c.config.Node.Attributes, name)
		} else {
			c.config.Node.Attributes[name] = newVal
		}
	}

	// update node links and resources from the diff created from
	// fingerprinting
	for name, newVal := range response.Links {
		oldVal := c.config.Node.Links[name]
		if oldVal == newVal {
			continue
		}

		nodeHasChanged = true
		if newVal == "" {
			delete(c.config.Node.Links, name)
		} else {
			c.config.Node.Links[name] = newVal
		}
	}

	// COMPAT(0.10): Remove in 0.10
	// update the response networks with the config
	// if we still have node changes, merge them
	if response.Resources != nil {
		response.Resources.Networks = updateNetworks(
			c.config.Node.Resources.Networks,
			response.Resources.Networks,
			c.config)
		if !c.config.Node.Resources.Equals(response.Resources) {
			c.config.Node.Resources.Merge(response.Resources)
			nodeHasChanged = true
		}
	}

	// update the response networks with the config
	// if we still have node changes, merge them
	if response.NodeResources != nil {
		response.NodeResources.Networks = updateNetworks(
			c.config.Node.NodeResources.Networks,
			response.NodeResources.Networks,
			c.config)
		if !c.config.Node.NodeResources.Equals(response.NodeResources) {
			c.config.Node.NodeResources.Merge(response.NodeResources)
			nodeHasChanged = true
		}
	}

	if nodeHasChanged {
		c.updateNodeLocked()
	}

	return c.configCopy.Node
}
435975
func (fpm FingerprintMatcher) FingerprintMatches(filename string, expected charmresource.Fingerprint) (bool, error) {
	open := fpm.Open
	if open == nil {
		open = func(filename string) (io.ReadCloser, error) { return os.Open(filename) }
	}
	generateFingerprint := fpm.GenerateFingerprint
	if generateFingerprint == nil {
		generateFingerprint = charmresource.GenerateFingerprint
	}

	file, err := open(filename)
	if os.IsNotExist(errors.Cause(err)) {
		return false, nil
	}
	if err != nil {
		return false, errors.Trace(err)
	}
	defer file.Close()

	fp, err := generateFingerprint(file)
	if err != nil {
		return false, errors.Trace(err)
	}
	matches := (fp.String() == expected.String())
	return matches, nil
}
1155910
func ExtractFingerprint(privateKeyPath, hashAlgo string) (Fingerprint, error) {
	output, err := exec.Command("ssh-keygen", "-l", "-v", "-E", hashAlgo, "-f", privateKeyPath).Output()
	if err != nil {
		return Fingerprint{}, err
	}

	i := bytes.IndexByte(output, '\n')
	if i == -1 {
		return Fingerprint{}, fmt.Errorf("could not parse fingerprint")
	}

	fields := fieldRegexp.FindSubmatch(output[:i])
	if len(fields) != captureCount {
		return Fingerprint{}, fmt.Errorf("could not parse fingerprint")
	}

	return Fingerprint{
		Hash:      string(fields[3]),
		Randomart: string(output[i+1:]),
	}, nil
}
246194
func PrivateKeyFingerprint(keyBytes []byte) (string, error) {
	signer, err := ssh.ParsePrivateKey(keyBytes)
	if err != nil {
		return "", trace.Wrap(err)
	}
	return Fingerprint(signer.PublicKey()), nil
}
1040507
func (i *instanceManager) handleFingerprintError() {
	di := &structs.DriverInfo{
		Healthy:           false,
		HealthDescription: "failed to fingerprint driver",
		UpdateTime:        time.Now(),
	}
	i.updateNodeFromDriver(i.id.Name, di)
}
528977
func labelSetToFastFingerprint(ls LabelSet) Fingerprint {
	if len(ls) == 0 {
		return Fingerprint(emptyLabelSignature)
	}

	var result uint64
	for labelName, labelValue := range ls {
		sum := hashNew()
		sum = hashAdd(sum, string(labelName))
		sum = hashAddByte(sum, SeparatorByte)
		sum = hashAdd(sum, string(labelValue))
		result ^= sum
	}
	return Fingerprint(result)
}
152116
func (p PublicKey) Fingerprint() string {
	h := make([]byte, 20)
	d := sha3.NewShake256()
	_, _ = d.Write([]byte{0x42})
	_ = binary.Write(d, binary.LittleEndian, p.PubKeyAlgo)
	_, _ = d.Write(p.PublicKey[:])
	_, _ = d.Read(h)
	return fmt.Sprintf("%x", h)
}
950090
func (pub *DSAPublicKey) Fingerprint() []byte {
	b := pub.serialize()
	if b == nil {
		return nil
	}

	h := fingerprintHashInstanceForVersion(3)

	h.Write(b[2:]) // if public key is DSA, ignore the leading 0x00 0x00 for the key type (according to spec)
	return h.Sum(nil)
}
94065
func (c *Client) Thumbprint(host string) string {
	host = hostAddr(host)
	c.hostsMu.Lock()
	defer c.hostsMu.Unlock()
	return c.hosts[host]
}
509136
private boolean matchesFingerprint(byte[] buffer, byte[] fingerprint)
   {
      return Arrays.equals(fingerprint, Arrays.copyOf(buffer, fingerprint.length));
   }
1003428
func (s *DescribeLunaClientOutput) SetCertificateFingerprint(v string) *DescribeLunaClientOutput {
	s.CertificateFingerprint = &v
	return s
}
410302
func (s *HostKeyAttributes) SetFingerprintSHA256(v string) *HostKeyAttributes {
	s.FingerprintSHA256 = &v
	return s
}