Пример #1
0
// FingerprintTriple generates a SHA-1 hash of the triple.
func FingerprintTriple(t *protocol.Triple) ([]byte, error) {
	data, err := t.Marshal()
	if err != nil {
		return nil, err
	}
	sum := sha1.Sum(data)
	return sum[:], nil
}
Пример #2
0
// FingerprintTriple generates a SHA-1 hash of the triple.
func FingerprintTriple(t *protocol.Triple) ([]byte, error) {
	h := sha1.New()
	data, err := t.Marshal()
	if err != nil {
		return nil, err
	}
	if _, err := h.Write(data); err != nil {
		return nil, err
	}
	return h.Sum(nil), nil
}
Пример #3
0
func (key *PrivateKey) SignTriple(t *protocol.Triple) error {
	var err error
	t.Author, err = key.AuthorID()
	if err != nil {
		return err
	}
	fingerprint, err := FingerprintTriple(t)
	if err != nil {
		return err
	}

	r, s, err := ecdsa.Sign(rand.Reader, (*ecdsa.PrivateKey)(key), fingerprint)
	if err != nil {
		return err
	}

	t.Sig = string(r.Bytes()) + string(s.Bytes())
	return nil
}