Repository: go-gitea/gitea
File: services/asymkey/sign.go (Go)

Code before:
// userHasPubkeys checks if a user has any public keys (GPG or SSH)
func userHasPubkeys(ctx context.Context, userID int64) (bool, error) {
	has, err := userHasPubkeysGPG(ctx, userID)
	if has || err != nil {
		return has, err
	}
	return userHasPubkeysSSH(ctx, userID)
}

// ErrWontSign explains the first reason why a commit would not be signed
// There may be other reasons - this is just the first reason found
type ErrWontSign struct {
	Reason signingMode
}

func (e *ErrWontSign) Error() string {
	return fmt.Sprintf("wont sign: %s", e.Reason)
}

// IsErrWontSign checks if an error is a ErrWontSign
func IsErrWontSign(err error) bool {
	_, ok := err.(*ErrWontSign)
	return ok
}

// PublicSigningKey gets the public signing key
func PublicSigningKey(ctx context.Context) (content, format string, err error) {
	signingKey, _ := git.GetSigningKey(ctx)
	if signingKey == nil {
		return "", "", nil
	}
	if signingKey.Format == git.SigningKeyFormatSSH {
		content, err := os.ReadFile(signingKey.KeyID)
		if err != nil {
			log.Error("Unable to read SSH public key file: %s, %v", signingKey, err)
			return "", signingKey.Format, err
		}
		return string(content), signingKey.Format, nil
	}

	content, stderr, err := process.GetManager().ExecDir(ctx, -1, setting.Git.HomePath,
		"gpg --export -a", "gpg", "--export", "-a", signingKey.KeyID)
	if err != nil {
		log.Error("Unable to get default signing key: %s, %s, %v", signingKey, stderr, err)
		return "", signingKey.Format, err
	}
	return content, signingKey.Format, nil
}

// SignInitialCommit determines if we should sign the initial commit to this repository
func SignInitialCommit(ctx context.Context, u *user_model.User) (bool, *git.SigningKey, *git.Signature, error) {

Review comment (suggestion):
```suggestion
// PublicSigningKey gets the public signing key of the entire instance
```

Code after:
// userHasPubkeys checks if a user has any public keys (GPG or SSH)
func userHasPubkeys(ctx context.Context, userID int64) (bool, error) {
	has, err := userHasPubkeysGPG(ctx, userID)
	if has || err != nil {
		return has, err
	}
	return userHasPubkeysSSH(ctx, userID)
}

// ErrWontSign explains the first reason why a commit would not be signed
// There may be other reasons - this is just the first reason found
type ErrWontSign struct {
	Reason signingMode
}

func (e *ErrWontSign) Error() string {
	return fmt.Sprintf("wont sign: %s", e.Reason)
}

// IsErrWontSign checks if an error is a ErrWontSign
func IsErrWontSign(err error) bool {
	_, ok := err.(*ErrWontSign)
	return ok
}

// PublicSigningKey gets the public signing key of the entire instance
func PublicSigningKey(ctx context.Context) (content, format string, err error) {
	signingKey, _ := git.GetSigningKey(ctx)
	if signingKey == nil {
		return "", "", nil
	}
	if signingKey.Format == git.SigningKeyFormatSSH {
		content, err := os.ReadFile(signingKey.KeyID)
		if err != nil {
			log.Error("Unable to read SSH public key file: %s, %v", signingKey, err)
			return "", signingKey.Format, err
		}
		return string(content), signingKey.Format, nil
	}

	content, stderr, err := process.GetManager().ExecDir(ctx, -1, setting.Git.HomePath,
		"gpg --export -a", "gpg", "--export", "-a", signingKey.KeyID)
	if err != nil {
		log.Error("Unable to get default signing key: %s, %s, %v", signingKey, stderr, err)
		return "", signingKey.Format, err
	}
	return content, signingKey.Format, nil
}

// SignInitialCommit determines if we should sign the initial commit to this repository
func SignInitialCommit(ctx context.Context, u *user_model.User) (bool, *git.SigningKey, *git.Signature, error) {