#!/bin/bash -u
# Copyright (c) 2019 Yubico AB. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

T=cred-rsa-h-p

sync() {
	mkdir ${T}
	ssh "${REMOTE}" "cd ${T}/afl-out && tar -cf- queue" | tar -C ${T} -xf-
}

run() {
	find ${T}/queue -type f | while read f; do
		cat "${f}" | LD_PRELOAD=${PRELOAD} build/examples/cred \
			-t rsa -r -k ${T}/pubkey -i ${T}/cred_id -h nodev \
			2>/dev/null 1>&2
	done
}

case "$1" in
sync)
	sync
	;;
run)
	run
	exit 0
	;;
*)
	echo unknown command "$1"
	exit 1
esac
