treewide: replace error assertions with errors.As

Change-Id: I369cc1dd8f745203f6f24093049d60d971acdf11
Reviewed-on: https://review.monogon.dev/c/monogon/+/3038
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/pkg/tpm/eventlog/internal/events.go b/metropolis/pkg/tpm/eventlog/internal/events.go
index 78d305c..c95e9dc 100644
--- a/metropolis/pkg/tpm/eventlog/internal/events.go
+++ b/metropolis/pkg/tpm/eventlog/internal/events.go
@@ -391,7 +391,8 @@
 	} else {
 		// A bug in shim may cause an event to be missing the SignatureOwner GUID.
 		// We handle this, but signal back to the caller using ErrSigMissingGUID.
-		if _, isStructuralErr := err.(asn1.StructuralError); isStructuralErr {
+		var structuralError asn1.StructuralError
+		if errors.As(err, &structuralError) {
 			var err2 error
 			cert, err2 = x509.ParseCertificate(b)
 			if err2 == nil {
diff --git a/metropolis/pkg/tpm/tpm.go b/metropolis/pkg/tpm/tpm.go
index a5a0ee1..785553d 100644
--- a/metropolis/pkg/tpm/tpm.go
+++ b/metropolis/pkg/tpm/tpm.go
@@ -476,7 +476,8 @@
 			// Use a full policy session for the EK
 			{Session: endorsementSession, Attributes: tpm2.AttrContinueSession},
 		}, tpm.akHandleCache, ekHandle, credBlob, secretChallenge)
-		if warn, ok := err.(tpm2.Warning); ok && warn.Code == tpm2.RCRetry {
+		var warn tpm2.Warning
+		if errors.As(err, &warn) && warn.Code == tpm2.RCRetry {
 			time.Sleep(100 * time.Millisecond)
 			continue
 		}