tenseleyflow/shithub / bcf83ca

Browse files

web/render: add verifiedReasonMessage template func

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
bcf83ca163473cffc703fd6cdf472c057cf6cf34
Parents
7f3aed3
Tree
ba9c202

1 changed file

StatusFile+-
M internal/web/render/render.go 37 0
internal/web/render/render.gomodified
@@ -359,6 +359,43 @@ func funcMap(octicon OcticonResolver) template.FuncMap {
359
 			}
359
 			}
360
 			return m, nil
360
 			return m, nil
361
 		},
361
 		},
362
+		// verifiedReasonMessage maps a sigverify.Reason string to a
363
+		// short user-facing explanation. Used by the _verified_badge
364
+		// partial's popover. Accepts the Reason as a string so the
365
+		// template doesn't need a type assertion.
366
+		"verifiedReasonMessage": verifiedReasonMessage,
367
+	}
368
+}
369
+
370
+// verifiedReasonMessage returns the popover body text for each
371
+// non-valid verification reason. "unsigned" never reaches the
372
+// popover (the badge isn't rendered at all in that case) so it's
373
+// omitted. The strings are user-facing copy; keep them short and
374
+// concrete.
375
+func verifiedReasonMessage(reason any) string {
376
+	r, ok := reason.(string)
377
+	if !ok {
378
+		// The template might pass a typed sigverify.Reason; Stringer
379
+		// would surface the underlying string. Try fmt-style fallback.
380
+		r = fmt.Sprintf("%s", reason)
381
+	}
382
+	switch r {
383
+	case "unknown_key":
384
+		return "This commit was signed but the public key isn't registered with shithub."
385
+	case "bad_email":
386
+		return "The commit signature doesn't match any of the registered user's emails."
387
+	case "unverified_email":
388
+		return "The commit signature matches an email the user hasn't verified."
389
+	case "malformed_signature":
390
+		return "The commit's signature couldn't be parsed."
391
+	case "invalid":
392
+		return "The commit's signature failed cryptographic verification."
393
+	case "expired_key":
394
+		return "The signing key was expired when this commit was made."
395
+	case "not_signing_key":
396
+		return "The key that signed this commit isn't authorized for signing."
397
+	default:
398
+		return "This commit's signature couldn't be verified."
362
 	}
399
 	}
363
 }
400
 }
364
 
401