Пример #1
0
// WriteKey calls the write callback chain to write keys to storage
func (kp KeyPool) WriteKey(key *signkeys.PublicKey) error {
	// Write currentKey to file
	data, err := key.Marshal()
	if err != nil {
		return err
	}
	if kp.WriteKeyCallback != nil {
		err := kp.WriteKeyCallback(key.KeyID[:], key.Usage, data)
		if err != nil {
			return err
		}
	}
	return nil
}
Пример #2
0
// loadKey adds a single key to the keypool. Without lock.
func (kp *KeyPool) loadKey(loadKey *signkeys.PublicKey) (*[signkeys.KeyIDSize]byte, error) {
	if kp.Generator.Usage != "" && loadKey.Usage != kp.Generator.Usage {
		// Don't load if usage is a mismatch
		return nil, ErrBadUsage
	}
	if loadKey.Expire < times.Now() {
		// Don't load expired keys
		return nil, ErrExpired
	}
	if !kp.HasVerifyKey(&loadKey.Signer, true) {
		// Don't load keys without matching signature
		return nil, ErrBadSigner
	}
	if !loadKey.Verify(&loadKey.Signer) {
		// Don't load keys without matching signature
		return nil, ErrBadSigner
	}
	if _, exists := kp.keys[loadKey.KeyID]; exists {
		return &loadKey.KeyID, ErrExists
	}
	kp.keys[loadKey.KeyID] = loadKey
	return &loadKey.KeyID, nil
}