Skip to content

Commit

Permalink
trusttier: add "identity" conversions to ToTrustTier
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
setrofim committed Sep 22, 2023
1 parent e82a194 commit 92728f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions trusttier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions trusttier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 92728f4

Please sign in to comment.