Beispiel #1
0
func (db *DB) AddKey(id string, k *data.Key) error {
	if k.Type != "ed25519" {
		return ErrWrongType
	}
	if id != k.ID() {
		return ErrWrongID
	}
	if len(k.Value.Public) != ed25519.PublicKeySize {
		return ErrInvalidKey
	}

	var key Key
	copy(key.Public[:], k.Value.Public)
	key.ID = id
	db.keys[id] = &key
	return nil
}
Beispiel #2
0
func Sign(s *data.Signed, k *data.Key) {
	id := k.ID()
	signatures := make([]data.Signature, 0, len(s.Signatures)+1)
	for _, sig := range s.Signatures {
		if sig.KeyID == id {
			continue
		}
		signatures = append(signatures, sig)
	}
	priv := [ed25519.PrivateKeySize]byte{}
	copy(priv[:], k.Value.Private)
	sig := ed25519.Sign(&priv, s.Signed)
	s.Signatures = append(signatures, data.Signature{
		KeyID:     id,
		Method:    "ed25519",
		Signature: sig[:],
	})
}