#!/bin/sh -ex

prfx=$VECTORS/rfc7520_5

test "`jose jwe dec -i $prfx.1.jwec  -k $prfx.1.jwk`"    = "`cat $prfx.1.pt`"
test "`jose jwe dec -i $prfx.1.jwef  -k $prfx.1.jwk`"    = "`cat $prfx.1.pt`"
test "`jose jwe dec -i $prfx.1.jweg  -k $prfx.1.jwk`"    = "`cat $prfx.1.pt`"

if jose alg | grep -q OAEP; then
    test "`jose jwe dec -i $prfx.2.jwec  -k $prfx.2.jwk`"    = "`cat $prfx.2.pt`"
    test "`jose jwe dec -i $prfx.2.jwef  -k $prfx.2.jwk`"    = "`cat $prfx.2.pt`"
    test "`jose jwe dec -i $prfx.2.jweg  -k $prfx.2.jwk`"    = "`cat $prfx.2.pt`"
fi

test "`jose jwe dec -i $prfx.3.jwec  -k $prfx.3.pwd`"    = "`cat $prfx.3.pt`"
test "`jose jwe dec -i $prfx.3.jwef  -k $prfx.3.pwd`"    = "`cat $prfx.3.pt`"
test "`jose jwe dec -i $prfx.3.jweg  -k $prfx.3.pwd`"    = "`cat $prfx.3.pt`"
test "`jose jwe dec -i $prfx.3.jwec  -k $prfx.3.jwk`"    = "`cat $prfx.3.pt`"
test "`jose jwe dec -i $prfx.3.jwef  -k $prfx.3.jwk`"    = "`cat $prfx.3.pt`"
test "`jose jwe dec -i $prfx.3.jweg  -k $prfx.3.jwk`"    = "`cat $prfx.3.pt`"

test "`jose jwe dec -i $prfx.4.jwec  -k $prfx.4.jwk`"    = "`cat $prfx.4.pt`"
test "`jose jwe dec -i $prfx.4.jwef  -k $prfx.4.jwk`"    = "`cat $prfx.4.pt`"
test "`jose jwe dec -i $prfx.4.jweg  -k $prfx.4.jwk`"    = "`cat $prfx.4.pt`"

test "`jose jwe dec -i $prfx.5.jwec  -k $prfx.5.jwk`"    = "`cat $prfx.5.pt`"
test "`jose jwe dec -i $prfx.5.jweg  -k $prfx.5.jwk`"    = "`cat $prfx.5.pt`"

test "`jose jwe dec -i $prfx.6.jwec  -k $prfx.6.jwk`"    = "`cat $prfx.6.pt`"
test "`jose jwe dec -i $prfx.6.jweg  -k $prfx.6.jwk`"    = "`cat $prfx.6.pt`"

test "`jose jwe dec -i $prfx.7.jwec  -k $prfx.7.jwk`"    = "`cat $prfx.7.pt`"
test "`jose jwe dec -i $prfx.7.jwef  -k $prfx.7.jwk`"    = "`cat $prfx.7.pt`"
test "`jose jwe dec -i $prfx.7.jweg  -k $prfx.7.jwk`"    = "`cat $prfx.7.pt`"

test "`jose jwe dec -i $prfx.8.jwec  -k $prfx.8.jwk`"    = "`cat $prfx.8.pt`"
test "`jose jwe dec -i $prfx.8.jwef  -k $prfx.8.jwk`"    = "`cat $prfx.8.pt`"
test "`jose jwe dec -i $prfx.8.jweg  -k $prfx.8.jwk`"    = "`cat $prfx.8.pt`"

test "`jose jwe dec -i $prfx.9.jwec  -k $prfx.9.jwk`"    = "`cat $prfx.9.pt`"
test "`jose jwe dec -i $prfx.9.jwef  -k $prfx.9.jwk`"    = "`cat $prfx.9.pt`"
test "`jose jwe dec -i $prfx.9.jweg  -k $prfx.9.jwk`"    = "`cat $prfx.9.pt`"

test "`jose jwe dec -i $prfx.10.jwef -k $prfx.10.jwk`"   = "`cat $prfx.10.pt`"
test "`jose jwe dec -i $prfx.10.jweg -k $prfx.10.jwk`"   = "`cat $prfx.10.pt`"

test "`jose jwe dec -i $prfx.11.jwef -k $prfx.11.jwk`"   = "`cat $prfx.11.pt`"
test "`jose jwe dec -i $prfx.11.jweg -k $prfx.11.jwk`"   = "`cat $prfx.11.pt`"

test "`jose jwe dec -i $prfx.12.jwef -k $prfx.12.jwk`"   = "`cat $prfx.12.pt`"
test "`jose jwe dec -i $prfx.12.jweg -k $prfx.12.jwk`"   = "`cat $prfx.12.pt`"

test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.1.jwk`" = "`cat $prfx.13.pt`"
test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.2.jwk`" = "`cat $prfx.13.pt`"
test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.3.jwk`" = "`cat $prfx.13.pt`"

# CVE-2023-50967 - test originally from https://github.com/P3ngu1nW/CVE_Request/blob/main/latch-jose.md
# This test is expected to fail quickly on patched systems.
prfx="${CVE_2023_50967}/cve-2023-50967"
! test "$(jose jwe dec -i $prfx.jwe -k $prfx.jwk)"