@@ -39,6 +39,8 @@ type Querier interface { |
| 39 | 39 | // Drives the 3-changes-per-60d cap. |
| 40 | 40 | CountRecentUsernameChanges(ctx context.Context, db DBTX, arg CountRecentUsernameChangesParams) (int64, error) |
| 41 | 41 | CountUnusedRecoveryCodes(ctx context.Context, db DBTX, userID int64) (int64, error) |
| 42 | + // Excludes revoked rows so the per-user cap (100) counts live keys. |
| 43 | + CountUserGPGKeys(ctx context.Context, db DBTX, userID int64) (int64, error) |
| 42 | 44 | CountUserSSHKeys(ctx context.Context, db DBTX, userID int64) (int64, error) |
| 43 | 45 | CountUserSSHKeysByKind(ctx context.Context, db DBTX, arg CountUserSSHKeysByKindParams) (int64, error) |
| 44 | 46 | CountUsers(ctx context.Context, db DBTX) (int64, error) |
@@ -81,6 +83,20 @@ type Querier interface { |
| 81 | 83 | GetUserEmailByAddress(ctx context.Context, db DBTX, email string) (UserEmail, error) |
| 82 | 84 | GetUserEmailByID(ctx context.Context, db DBTX, id int64) (UserEmail, error) |
| 83 | 85 | GetUserEmailByVerificationHash(ctx context.Context, db DBTX, verificationTokenHash []byte) (UserEmail, error) |
| 86 | + // Scoped single-key lookup for REST GET-by-id. user_id filter prevents |
| 87 | + // cross-user reads (existence-leak-safe: returns no row if the id |
| 88 | + // belongs to another user). |
| 89 | + GetUserGPGKey(ctx context.Context, db DBTX, arg GetUserGPGKeyParams) (UserGpgKey, error) |
| 90 | + // Uniqueness probe used by the add path to surface a friendly |
| 91 | + // "this key is already registered" error before the unique index |
| 92 | + // violation. Returns any row matching the fingerprint regardless of |
| 93 | + // which user owns it (global uniqueness is the contract). |
| 94 | + GetUserGPGKeyByFingerprint(ctx context.Context, db DBTX, fingerprint string) (UserGpgKey, error) |
| 95 | + // Hot path for commit/tag signature verification. The signature |
| 96 | + // packet carries the signing subkey's fingerprint; this query |
| 97 | + // resolves it back to the primary key (and via FK to the user). |
| 98 | + // Index lookup via the partial unique index. |
| 99 | + GetUserGPGSubkeyByFingerprint(ctx context.Context, db DBTX, fingerprint string) (UserGpgSubkey, error) |
| 84 | 100 | // Like GetUserByID but returns the row even when deleted_at IS NOT NULL. |
| 85 | 101 | GetUserIncludingDeleted(ctx context.Context, db DBTX, id int64) (User, error) |
| 86 | 102 | // Single-key lookup for the REST GET-by-id endpoint. user_id filter so |
@@ -102,6 +118,18 @@ type Querier interface { |
| 102 | 118 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 103 | 119 | InsertRecoveryCode(ctx context.Context, db DBTX, arg InsertRecoveryCodeParams) error |
| 104 | 120 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 121 | + // Inserts a parsed primary GPG key. Subkeys land in user_gpg_subkeys |
| 122 | + // in the same transaction (see InsertUserGPGSubkey). expires_at is |
| 123 | + // nullable; many keys have no expiration. revoked_at stays NULL on |
| 124 | + // insert; soft-delete sets it. |
| 125 | + InsertUserGPGKey(ctx context.Context, db DBTX, arg InsertUserGPGKeyParams) (UserGpgKey, error) |
| 126 | + // SPDX-License-Identifier: AGPL-3.0-or-later |
| 127 | + // One row per subkey of a primary key. Always inserted in the same |
| 128 | + // transaction as the parent InsertUserGPGKey so the verification |
| 129 | + // hot path's fingerprint lookup is consistent with the REST nested |
| 130 | + // shape. |
| 131 | + InsertUserGPGSubkey(ctx context.Context, db DBTX, arg InsertUserGPGSubkeyParams) (UserGpgSubkey, error) |
| 132 | + // SPDX-License-Identifier: AGPL-3.0-or-later |
| 105 | 133 | InsertUserSSHKey(ctx context.Context, db DBTX, arg InsertUserSSHKeyParams) (UserSshKey, error) |
| 106 | 134 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 107 | 135 | InsertUserToken(ctx context.Context, db DBTX, arg InsertUserTokenParams) (UserToken, error) |
@@ -113,7 +141,14 @@ type Querier interface { |
| 113 | 141 | // MarkUserEmailPrimaryVerified after the user clicks the verification link. |
| 114 | 142 | LinkUserPrimaryEmail(ctx context.Context, db DBTX, arg LinkUserPrimaryEmailParams) error |
| 115 | 143 | ListAuditLogForTarget(ctx context.Context, db DBTX, arg ListAuditLogForTargetParams) ([]AuthAuditLog, error) |
| 144 | + // Reads all live subkeys for one primary; used when invalidating the |
| 145 | + // verification cache on primary soft-delete (every dependent subkey |
| 146 | + // needs its cache rows stamped invalidated too). |
| 147 | + ListSubkeysForGPGKey(ctx context.Context, db DBTX, gpgKeyID int64) ([]UserGpgSubkey, error) |
| 116 | 148 | ListUserEmailsForUser(ctx context.Context, db DBTX, userID int64) ([]UserEmail, error) |
| 149 | + // Paginated list for the REST surface; HTML settings page reuses with |
| 150 | + // a generous limit and no offset. |
| 151 | + ListUserGPGKeys(ctx context.Context, db DBTX, arg ListUserGPGKeysParams) ([]UserGpgKey, error) |
| 117 | 152 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 118 | 153 | ListUserNotificationPrefs(ctx context.Context, db DBTX, userID int64) ([]UserNotificationPref, error) |
| 119 | 154 | ListUserSSHKeys(ctx context.Context, db DBTX, userID int64) ([]UserSshKey, error) |
@@ -148,10 +183,22 @@ type Querier interface { |
| 148 | 183 | // user and is verified. |
| 149 | 184 | SetUserEmailPrimary(ctx context.Context, db DBTX, arg SetUserEmailPrimaryParams) error |
| 150 | 185 | SetVerificationToken(ctx context.Context, db DBTX, arg SetVerificationTokenParams) error |
| 186 | + // Stamps revoked_at on every live subkey of a primary. Called in the |
| 187 | + // same transaction as SoftDeleteUserGPGKey so the partial unique index |
| 188 | + // frees up the fingerprint for re-upload if the user rotates. |
| 189 | + SoftDeleteSubkeysForGPGKey(ctx context.Context, db DBTX, gpgKeyID int64) error |
| 151 | 190 | SoftDeleteUser(ctx context.Context, db DBTX, id int64) error |
| 191 | + // Scoped soft-delete: stamps revoked_at, preserves the row for audit |
| 192 | + // continuity. Returns the number of rows affected so the handler can |
| 193 | + // distinguish "not found" from "deleted" without a follow-up query. |
| 194 | + SoftDeleteUserGPGKey(ctx context.Context, db DBTX, arg SoftDeleteUserGPGKeyParams) (int64, error) |
| 152 | 195 | SuspendUser(ctx context.Context, db DBTX, arg SuspendUserParams) error |
| 153 | 196 | TouchDeviceAuthorizationPoll(ctx context.Context, db DBTX, id int64) error |
| 154 | 197 | TouchSSHKeyLastUsed(ctx context.Context, db DBTX, arg TouchSSHKeyLastUsedParams) error |
| 198 | + // Best-effort last-used stamp called from the verification path when |
| 199 | + // a signature successfully resolves to this key. No timeout / error |
| 200 | + // propagation; the caller fires-and-forgets via a goroutine. |
| 201 | + TouchUserGPGKeyLastUsed(ctx context.Context, db DBTX, id int64) error |
| 155 | 202 | TouchUserLastLogin(ctx context.Context, db DBTX, id int64) error |
| 156 | 203 | TouchUserTokenLastUsed(ctx context.Context, db DBTX, arg TouchUserTokenLastUsedParams) error |
| 157 | 204 | // Clears the suspended state. Mirrors SuspendUser; used by the |