#!/bin/bash
#
# Test pkcs15-init
#
# Run this from the regression test directory.

. functions

p15_init --no-so-pin
p15_set_pin -a 01
p15_gen_key rsa/1024 -a 01 --key-usage decrypt
p15_exp_key key.pem

msg "Encrypting message (pkcs1 padding)"
echo lalla > $p15temp/message
run_check_status openssl rsautl -encrypt \
	-pubin -inkey $p15temp/key.pem \
	-in $p15temp/message \
	-out $p15temp/encrypted

run_check_status $p15crypt --decipher --pkcs1 \
	--input $p15temp/encrypted \
	--output $p15temp/decrypted \
	--pin 0000

cmp $p15temp/message $p15temp/decrypted \
	|| fail "Decrypted file does not match plain text file"
success

p15_erase --secret @01=0000
