Exemple #1
0
// DelHashChain deletes the hash chain for the given domain.
func (keyDB *KeyDB) DelHashChain(domain string) error {
	dmn := identity.MapDomain(domain)
	if _, err := keyDB.delHashChainQuery.Exec(dmn); err != nil {
		return err
	}
	return nil
}
Exemple #2
0
// GetHashChainEntry returns the hash chain entry for the given domain and
// position from keydb.
func (keyDB *KeyDB) GetHashChainEntry(domain string, position uint64) (string, error) {
	var entry string
	dmn := identity.MapDomain(domain)
	err := keyDB.getHashChainEntryQuery.QueryRow(dmn, position).Scan(&entry)
	switch {
	case err != nil:
		return "", log.Error(err)
	default:
		return entry, nil
	}
}
Exemple #3
0
// AddHashChainEntry adds the hash chain entry at position for the given
// domain to keyDB.
func (keyDB *KeyDB) AddHashChainEntry(
	domain string,
	position uint64,
	entry string,
) error {
	dmn := identity.MapDomain(domain)
	_, err := keyDB.addHashChainEntryQuery.Exec(dmn, position, entry)
	if err != nil {
		return err
	}
	return nil
}
Exemple #4
0
// GetLastHashChainEntry returns the last hash chain entry for the given domain.
func (keyDB *KeyDB) GetLastHashChainEntry(domain string) (string, error) {
	dmn := identity.MapDomain(domain)
	pos, found, err := keyDB.GetLastHashChainPos(dmn)
	if err != nil {
		return "", err
	}
	if !found {
		return "", log.Errorf("keydb: no entry found for domain '%s'", dmn)
	}
	entry, err := keyDB.GetHashChainEntry(dmn, pos)
	if err != nil {
		return "", err
	}
	return entry, nil
}
Exemple #5
0
// GetLastHashChainPos returns the last hash chain position for the given
// domain from keydb.
// The return value found indicates if a hash chain entry for domain exists.
func (keyDB *KeyDB) GetLastHashChainPos(domain string) (
	pos uint64,
	found bool,
	err error,
) {
	dmn := identity.MapDomain(domain)
	err = keyDB.getLastHashChainPosQuery.QueryRow(dmn).Scan(&pos)
	switch {
	case err == sql.ErrNoRows:
		return 0, false, nil
	case err != nil:
		return 0, false, log.Error(err)
	default:
		return pos, true, nil
	}
}
Exemple #6
0
// GetPrivateIdentitiesForDomain returns all private identities for the given
// domain from keyDB.
func (keyDB *KeyDB) GetPrivateIdentitiesForDomain(domain string) ([]string, error) {
	var identities []string
	all, err := keyDB.GetPrivateIdentities()
	if err != nil {
		return nil, err
	}
	dmn := identity.MapDomain(domain)
	for _, id := range all {
		_, idDomain, err := identity.Split(id)
		if err != nil {
			return nil, err
		}
		if idDomain == dmn {
			identities = append(identities, id)
		}
	}
	return identities, nil
}