#!/bin/sh
# Attaching the signature to the PE/MSI file.

. $(dirname $0)/../test_library

# PE file
test_name="321. Attaching the signature to the PE file"
printf "\n%s\n" "$test_name"
if [ -s "test.exe" ]
  then
    faketime -f '@2019-01-01 00:00:00' /bin/bash -c '
        script_path=$(pwd)
        ../../osslsigncode attach-signature -sigin "sign_pe.pem" \
            -in "test.exe" -out "test_321.exe"'
    verify_signature "$?" "321" "exe" "UNUSED_PATTERN" "sha256sum" "ASCII" "osslsigncode" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

# CAB file
# Command is not supported for non-PE/non-MSI files

# MSI file
test_name="322. Attaching the signature to the MSI file"
printf "\n%s\n" "$test_name"
if [ -s "sample.msi" ]
  then
    faketime -f '@2019-01-01 00:00:00' /bin/bash -c '
        script_path=$(pwd)
        ../../osslsigncode attach-signature -sigin "sign_msi.pem" \
            -in "sample.msi" -out "test_322.msi"'
    verify_signature "$?" "322" "msi" "UNUSED_PATTERN" "sha256sum" "ASCII" "osslsigncode" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

exit 0
