From 92728f463ba7b96b31e37abc1e38e4680ce4fa2c Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Fri, 22 Sep 2023 12:57:54 +0100 Subject: [PATCH] trusttier: add "identity" conversions to ToTrustTier Allow TrustTier and *TrustTier as valid input types for ToTrustTier(). This is something that already exists for ToTrustClaim and should have been implemented for ToTrustTier as well. Signed-off-by: Sergei Trofimov --- trusttier.go | 4 ++++ trusttier_test.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/trusttier.go b/trusttier.go index 2de7e51..28c0fc0 100644 --- a/trusttier.go +++ b/trusttier.go @@ -152,6 +152,10 @@ func ToTrustTier(v interface{}) (*TrustTier, error) { err = fmt.Errorf("not a valid TrustTier value: %v (%d)", t, int(i)) } } + case TrustTier: + tier = t + case *TrustTier: + tier = *t default: err = fmt.Errorf("cannot convert %v (type %T) to TrustTier", t, t) } diff --git a/trusttier_test.go b/trusttier_test.go index 71bcdfe..5a69597 100644 --- a/trusttier_test.go +++ b/trusttier_test.go @@ -163,4 +163,13 @@ func TestTrustTier_ToTrustTier(t *testing.T) { tt, err = ToTrustTier(UnrecognizedHardwareClaim) require.NoError(t, err) assert.Equal(t, TrustTierContraindicated, *tt) + + tt, err = ToTrustTier(TrustTierContraindicated) + require.NoError(t, err) + assert.Equal(t, TrustTierContraindicated, *tt) + + taff := TrustTierAffirming + tt, err = ToTrustTier(&taff) + require.NoError(t, err) + assert.Equal(t, TrustTierAffirming, *tt) }